/**
  * @param ClassName      $className
  * @param string         $propertyName
  * @param Exception|null $previous
  */
 public function __construct(ClassName $className, $propertyName, Exception $previous = null)
 {
     $this->typeCheck = TypeCheck::get(__CLASS__, func_get_args());
     $this->className = $className;
     $this->propertyName = $propertyName;
     parent::__construct(sprintf("Undefined property '%s::\$%s'.", $className->string(), $propertyName), 0, $previous);
 }
Exemple #2
0
 /**
  * @param ClassName                 $className
  * @param array<array<ClassName>>   $usedClasses
  * @param array<MethodDefinition>   $methods
  * @param array<PropertyDefinition> $properties
  */
 public function __construct(ClassName $className, array $usedClasses = array(), array $methods = array(), array $properties = array())
 {
     $this->typeCheck = TypeCheck::get(__CLASS__, func_get_args());
     $this->className = $className->toAbsolute();
     $this->methods = $methods;
     $this->properties = $properties;
     if ($className->hasParent()) {
         $namespaceName = $className->parent();
     } else {
         $namespaceName = null;
     }
     $this->classNameResolver = new ClassNameResolver($namespaceName, $usedClasses);
 }
 /**
  * @param ClassName $className
  *
  * @return ClassName
  */
 public function shorten(ClassName $className)
 {
     if (!$className->isAbsolute()) {
         return $className;
     }
     foreach ($this->usedClasses() as $tuple) {
         list($usedClass, $as) = $tuple;
         if ($this->comparator()->equals($usedClass, $className)) {
             return $as;
         }
     }
     if (null !== $this->namespaceName() && $this->namespaceName()->hasDescendant($className)) {
         return $className->stripNamespace($this->namespaceName());
     }
     return $className;
 }
 protected function addDataProvider(DataProvider $dataProvider)
 {
     $this->dataProviders[ClassName::fromString(get_class($dataProvider))->shortName()->string()] = $dataProvider;
     return $this;
 }
Exemple #5
0
 /**
  * @param MethodDefinition $methodDefinition
  * @param ClassName        $expectedfacadeClassName
  *
  * @return boolean
  */
 protected function methodHasConstructorStaticCall(MethodDefinition $methodDefinition, ClassName $expectedfacadeClassName)
 {
     $this->typeCheck->methodHasConstructorStaticCall(func_get_args());
     $hasCall = false;
     $callPattern = sprintf('/^\\s*%s\\s*::\\s*get\\s*\\(\\s*__CLASS__\\s*,\\s*\\\\?func_get_args\\s*\\(\\s*\\)\\s*\\)\\s*;$/', preg_quote($expectedfacadeClassName->string(), '/'));
     $firstStatement = $this->parseFirstMethodStatement($methodDefinition->source());
     if (preg_match($callPattern, $firstStatement)) {
         $hasCall = true;
     }
     return $hasCall;
 }
 /**
  * @param ClassName      $className
  * @param Exception|null $previous
  */
 public function __construct(ClassName $className, Exception $previous = null)
 {
     $this->className = $className;
     parent::__construct(sprintf("Invalid used class alias '%s'.", $className->string()), 0, $previous);
 }
 /**
  * @param ClassName      $className
  * @param Exception|null $previous
  */
 public function __construct(ClassName $className, Exception $previous = null)
 {
     $this->className = $className;
     parent::__construct(sprintf("Unable to join absolute class name '%s'.", $className->string()), 0, $previous);
 }
 /**
  * @param ClassName $className
  *
  * @return string
  */
 protected function PSRPath(ClassName $className)
 {
     $this->typeCheck->PSRPath(func_get_args());
     return str_replace('\\', '/', $className->parent()->string()) . '/' . str_replace('_', '/', $className->shortName()->string()) . '.php';
 }
 /**
  * @param RuntimeConfiguration $configuration
  * @param ClassDefinition      $classDefinition
  *
  * @return ClassName
  */
 protected function validatorClassName(RuntimeConfiguration $configuration, ClassDefinition $classDefinition)
 {
     $this->typeCheck->validatorClassName(func_get_args());
     $classNameAtoms = $configuration->validatorNamespace()->atoms();
     $classNameAtoms[] = 'Validator';
     if ($classDefinition->className()->hasParent()) {
         $classNameAtoms = array_merge($classNameAtoms, $classDefinition->className()->parent()->atoms());
     }
     $classNameAtoms[] = sprintf('%sTypeCheck', $classDefinition->className()->shortName()->string());
     return ClassName::fromAtoms($classNameAtoms, true);
 }
Exemple #10
0
 /**
  * @param ClassName $namespaceName
  *
  * @return ClassName
  */
 public function stripNamespace(ClassName $namespaceName)
 {
     if (!$namespaceName->hasDescendant($this)) {
         throw new Exception\NamespaceMismatchException($this, $namespaceName);
     }
     $atoms = $this->atoms();
     array_splice($atoms, 0, count($namespaceName->atoms()));
     return static::fromAtoms($atoms, false);
 }
Exemple #11
0
 protected static function configuration()
 {
     return new \Eloquent\Typhoon\Configuration\RuntimeConfiguration(\Eloquent\Cosmos\ClassName::fromString('\\Typhoon'), false);
 }
 /**
  * @param mixed $data
  *
  * @return Configuration
  */
 protected function buildConfiguration($data)
 {
     $this->typeCheck->buildConfiguration(func_get_args());
     $this->validateData($data);
     $configuration = new Configuration($data->{'output-path'}, $data->{'source-paths'});
     if (property_exists($data, ConfigurationOption::LOADER_PATHS()->value())) {
         $configuration->setLoaderPaths($data->{'loader-paths'});
     }
     if (property_exists($data, ConfigurationOption::VALIDATOR_NAMESPACE()->value())) {
         $configuration->setValidatorNamespace(ClassName::fromString($data->{'validator-namespace'}));
     }
     if (property_exists($data, ConfigurationOption::USE_NATIVE_CALLABLE()->value())) {
         $configuration->setUseNativeCallable($data->{'use-native-callable'});
     }
     return $configuration;
 }
 /**
  * @param ReflectionParameter $reflector
  *
  * @return Parameter
  */
 public function parseParameterReflector(ReflectionParameter $reflector)
 {
     $this->typeCheck->parseParameterReflector(func_get_args());
     if ($class = $reflector->getClass()) {
         $type = new ObjectType(ClassName::fromString($class->getName())->toAbsolute());
     } elseif ($reflector->isArray()) {
         $type = new TraversableType(new ArrayType(), new MixedType(), new MixedType());
     } else {
         $reflectorReflector = new ReflectionObject($reflector);
         if ($reflectorReflector->hasMethod('isCallable') && $reflector->isCallable()) {
             $type = new CallableType();
         } else {
             $type = new MixedType();
         }
     }
     if (!$type instanceof MixedType && $reflector->allowsNull()) {
         $type = new OrType(array($type, new NullType()));
     }
     return new Parameter($reflector->getName(), $type, null, $reflector->isOptional(), $reflector->isPassedByReference());
 }
 /**
  * @param ClassName      $className
  * @param ClassName      $namespaceName
  * @param Exception|null $previous
  */
 public function __construct(ClassName $className, ClassName $namespaceName, Exception $previous = null)
 {
     $this->className = $className;
     $this->namespaceName = $namespaceName;
     parent::__construct(sprintf("Class '%s' does not belong to namespace '%s'.", $className->string(), $namespaceName->string()), 0, $previous);
 }
Exemple #15
0
 /**
  * @param array<string|array> &$tokens
  *
  * @return ClassName
  */
 protected function parseClassName(array &$tokens)
 {
     $this->typeCheck->parseClassName(func_get_args());
     do {
         $token = $this->normalizeToken(next($tokens));
     } while (T_WHITESPACE === $token[0]);
     return ClassName::fromAtoms(array($token[1]), false);
 }
 /**
  * @param ClassName $validatorNamespace
  */
 public function setValidatorNamespace(ClassName $validatorNamespace)
 {
     $this->typeCheck->setValidatorNamespace(func_get_args());
     $this->validatorNamespace = $validatorNamespace->toAbsolute();
 }
Exemple #17
0
 /**
  * @param ClassName      $className
  * @param Exception|null $previous
  */
 public function __construct(ClassName $className, Exception $previous = null)
 {
     $this->className = $className;
     parent::__construct(sprintf("Unable to determine parent for class '%s'.", $className->string()), 0, $previous);
 }