Пример #1
0
 /**
  * Sets default value of argument and marks it as "has default value"
  *
  * @param mixed $defaultValue
  * @throws \BadMethodCallException when argument is nullable
  * @return self
  */
 public function setDefaultValue($defaultValue)
 {
     if ($this->isNullable) {
         throw new \BadMethodCallException('Cannot set default value for argument since it\'s nullable');
     }
     $this->hasDefaultValue = true;
     if ($this->type->isTargetType($defaultValue)) {
         $defaultValue = $this->type->create($defaultValue);
     }
     $this->defaultValue = $defaultValue;
     return $this;
 }
 public function testExtract()
 {
     $transform = function ($value) {
         return $value . ' extracted';
     };
     $this->type->expects($this->atLeastOnce())->method('extract')->will($this->returnCallback($transform));
     $tab = range(1, 10);
     $expected = array_map($transform, $tab);
     $this->assertEquals($expected, $this->object->extract($tab));
     $value = new \ArrayIterator($tab);
     $this->assertEquals($expected, $this->object->extract($value));
 }
 /**
  * {@inheritDoc}
  */
 public function extract($value)
 {
     if ($value === null) {
         if ($this->isNullable) {
             return null;
         }
         if ($this->hasDefaultValue) {
             return $this->type->extract($this->defaultValue);
         }
     }
     return $this->type->extract($value);
 }
Пример #4
0
 /**
  * @return TypeCheckInterface
  */
 protected function createTypeCheck()
 {
     return new StrictMapTypeCheck($this->keyType->getTypeCheck(), $this->valueType->getTypeCheck());
 }
Пример #5
0
 /**
  * {@inheritDoc}
  */
 protected function createTypeCheck()
 {
     return new TraversableOf($this->type->getTypeCheck());
 }