Your project must not contain invalid function or method calls 13
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_call
- */
- protected function getScalarValue($value)
- {
- $scalarValue = null;
- if (0 === stripos((string) $value, '::')) {
- $scalarValue = substr($value, 2);
- } elseif (false !== stripos((string) $value, '::') || false !== stripos((string) $value, 'new ') || false !== stripos((string) $value, '(') || false !== stripos((string) $value, ')')) {
- $scalarValue = $value;
- }
- return $scalarValue;
- class PhpAnnotationBlock extends AbstractElement
- {
- public function __construct(array $annotations = [])
- {
- parent::__construct('_');
- $this->setAnnotations($annotations);
- }
- /**
- * @param mixed $child
- *
- if (!$this->childIsValid($child)) {
- parent::addChild($child);
- return $this;
- }
- $this->children[] = static::transformAnnotation($child);
- return $this;
- }
- public function getPhpDeclaration(): string
- public function __construct(string $name, bool $abstract = false, $extends = null, array $interfaces = [])
- {
- parent::__construct($name);
- $this
- ->setAbstract($abstract)
- ->setExtends($extends)
- ->setInterfaces($interfaces)
- ;
- }
- public function setAbstract(bool $abstract): self
- {
- parent::__construct($name);
- $this
- ->setAbstract($abstract)
- ->setExtends($extends)
- ->setInterfaces($interfaces)
- ;
- }
- public function setAbstract(bool $abstract): self
- {
- return $this->interfaces;
- }
- public function getPhpDeclaration(): string
- {
- return trim(sprintf('%s%s %s%s%s', $this->getPhpAbstract(), static::PHP_DECLARATION, $this->getPhpName(), $this->getPhpExtends(), $this->getPhpInterfaces()));
- }
- /**
- * defines authorized children element types.
- *
- protected function getPhpExtends(): string
- {
- $extends = $this->getExtends();
- return empty($extends) ? '' : sprintf(' %s %s', static::PHP_EXTENDS_KEYWORD, $extends instanceof PhpClass ? $extends->getName() : $extends);
- }
- protected function getPhpInterfaces(): string
- {
- $interfaces = [];
- $interfaces = [];
- foreach ($this->getInterfaces() as $interface) {
- $interfaces[] = $this->getPhpInterface($interface);
- }
- return empty($interfaces) ? '' : sprintf(' %s%s', static::PHP_IMPLEMENTS_KEYWORD, implode(',', $interfaces));
- }
- /**
- * @param PhpClass|string $interface
- */
- private $value;
- public function __construct(string $name, $value = null)
- {
- parent::__construct($name);
- $this->setValue($value);
- }
- /**
- * @param int|string $value
- */
- public static function parametersAreValid(array $parameters): bool
- {
- $valid = true;
- foreach ($parameters as $parameter) {
- $valid &= static::parameterIsValid($parameter);
- }
- return (bool) $valid;
- }
- {
- $parameters = $this->getParameters();
- $phpParameters = [];
- if (is_array($parameters) && !empty($parameters)) {
- foreach ($parameters as $parameter) {
- $phpParameters[] = $parameter->getPhpDeclaration();
- }
- }
- return implode(', ', $phpParameters);
- }
- use TypeHintedElementTrait;
- public function __construct(string $name, $value = null, $type = null)
- {
- parent::__construct($name, $value);
- $this->setType($type);
- }
- public function getPhpDeclaration(): string
- {
- return sprintf('%s%s', $this->getPhpType(), parent::getPhpDeclaration());
- use TypeHintedElementTrait;
- public function __construct(string $name, $value = null, string $access = self::ACCESS_PUBLIC, $type = null)
- {
- parent::__construct($name, $value);
- $this->setType($type);
- $this->setAccess($access);
- }
- public function getPhpDeclaration(): string
- {
Your project should not use invalid return types 2
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_return_typehint
- abstract public function getPhpName(): string;
- protected function getFinalValue(): ?string
- {
- if (is_scalar($this->getValue()) && !is_null($scalarValue = $this->getScalarValue($this->getValue()))) {
- return $scalarValue;
- }
- if (is_null($this->getValue())) {
- return 'null';
- }
- abstract public function getPhpName(): string;
- protected function getFinalValue(): ?string
- {
- if (is_scalar($this->getValue()) && !is_null($scalarValue = $this->getScalarValue($this->getValue()))) {
- return $scalarValue;
- }
- if (is_null($this->getValue())) {
- return 'null';
- }
Your project should not use invalid parameter and return typehints 48
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_typehint
- /**
- * @var mixed
- */
- protected $value;
- public function setValue($value): AbstractElement
- {
- if (!$this->getAcceptNonScalarValue() && !is_scalar($value) && !is_null($value)) {
- throw new \InvalidArgumentException(sprintf('Value of type "%s" is not a valid scalar value for %s object', gettype($value), $this->getCalledClass()));
- }
- $this->value = $value;
- /**
- * @var mixed
- */
- protected $value;
- public function setValue($value): AbstractElement
- {
- if (!$this->getAcceptNonScalarValue() && !is_scalar($value) && !is_null($value)) {
- throw new \InvalidArgumentException(sprintf('Value of type "%s" is not a valid scalar value for %s object', gettype($value), $this->getCalledClass()));
- }
- $this->value = $value;
- }
- return $scalarValue;
- }
- protected function getAnyValue($value): string
- {
- if (is_array($value)) {
- $exportedValue = empty($value) ? '[]' : implode("\n", array_map(fn ($line): string => 'array (' === $line ? '[' : (')' === $line ? ']' : $line), explode("\n", var_export($value, true))));
- } else {
- $exportedValue = var_export($value, true);
- }
- return $scalarValue;
- }
- protected function getAnyValue($value): string
- {
- if (is_array($value)) {
- $exportedValue = empty($value) ? '[]' : implode("\n", array_map(fn ($line): string => 'array (' === $line ? '[' : (')' === $line ? ']' : $line), explode("\n", var_export($value, true))));
- } else {
- $exportedValue = var_export($value, true);
- namespace WsdlToPhp\PhpGenerator\Element;
- class PhpAnnotationBlock extends AbstractElement
- {
- public function __construct(array $annotations = [])
- {
- parent::__construct('_');
- $this->setAnnotations($annotations);
- }
- /**
- * @param array[]|PhpAnnotation[]|string[] $annotations
- *
- * @throws \InvalidArgumentException
- */
- protected function setAnnotations(array $annotations): self
- {
- if (!static::annotationsAreValid($annotations)) {
- throw new \InvalidArgumentException('Annotations are not valid');
- }
- $this->children = static::transformAnnotations($annotations);
- /**
- * @param array[]|PhpAnnotation[]|string[] $annotations
- *
- * @return PhpAnnotation[]
- */
- protected static function transformAnnotations(array $annotations): array
- {
- $finalAnnotations = [];
- foreach ($annotations as $annotation) {
- $finalAnnotations[] = static::transformAnnotation($annotation);
- }
- /**
- * @param array|PhpAnnotation|string $annotation
- *
- * @throws \InvalidArgumentException
- */
- protected static function transformAnnotation($annotation): PhpAnnotation
- {
- if ($annotation instanceof PhpAnnotation) {
- return $annotation;
- }
- if (is_string($annotation)) {
- }
- /**
- * @param array[]|PhpAnnotation[]|string[] $annotations
- */
- protected static function annotationsAreValid(array $annotations): bool
- {
- $valid = true;
- foreach ($annotations as $annotation) {
- $valid &= static::annotationIsValid($annotation);
- }
- }
- /**
- * @param array|PhpAnnotation|string $annotation
- */
- protected static function annotationIsValid($annotation): bool
- {
- return static::stringIsValid($annotation, false) || (is_array($annotation) && array_key_exists('content', $annotation)) || $annotation instanceof PhpAnnotation;
- }
- }
- /**
- * @var PhpClass[]|string[]
- */
- protected array $interfaces;
- public function __construct(string $name, bool $abstract = false, $extends = null, array $interfaces = [])
- {
- parent::__construct($name);
- $this
- ->setAbstract($abstract)
- ->setExtends($extends)
- /**
- * @var PhpClass[]|string[]
- */
- protected array $interfaces;
- public function __construct(string $name, bool $abstract = false, $extends = null, array $interfaces = [])
- {
- parent::__construct($name);
- $this
- ->setAbstract($abstract)
- ->setExtends($extends)
- /**
- * @var int|string
- */
- private $value;
- public function __construct(string $name, $value = null)
- {
- parent::__construct($name);
- $this->setValue($value);
- }
- }
- return 0 === count($strings) ? '' : sprintf(self::STATEMENT, implode(', ', $strings));
- }
- public function addChild($child): AbstractElement
- {
- /** @var AbstractElement $child */
- if ($this->childIsValid($child) && $child->getName() === $this->getName()) {
- throw new \InvalidArgumentException(sprintf('The current directive named %s can\'t contain a child of same directive name', $this->getName()));
- }
- */
- protected array $parameters;
- protected ?string $returnType;
- public function __construct(string $name, array $parameters = [], ?string $returnType = null)
- {
- parent::__construct($name);
- $this
- ->setParameters($parameters)
- ->setReturnType($returnType)
- ->setParameters($parameters)
- ->setReturnType($returnType)
- ;
- }
- public function setParameters(array $parameters): self
- {
- if (!static::parametersAreValid($parameters)) {
- throw new \InvalidArgumentException('Parameters are invalid');
- }
- $this->parameters = static::transformParameters($parameters);
- return $this;
- }
- public static function transformParameters(array $parameters): array
- {
- $finalParameters = [];
- foreach ($parameters as $parameter) {
- $finalParameters[] = static::transformParameter($parameter);
- }
- }
- return $finalParameters;
- }
- public static function transformParameter($parameter): PhpFunctionParameter
- {
- if ($parameter instanceof PhpFunctionParameter) {
- return $parameter;
- }
- if (is_array($parameter)) {
- }
- return new PhpFunctionParameter($parameter, PhpFunctionParameter::NO_VALUE);
- }
- public static function parametersAreValid(array $parameters): bool
- {
- $valid = true;
- foreach ($parameters as $parameter) {
- $valid &= static::parameterIsValid($parameter);
- }
- }
- /**
- * @param array|PhpFunctionParameter|string $parameter
- */
- public static function parameterIsValid($parameter): bool
- {
- return static::stringIsValid($parameter) || (is_array($parameter) && array_key_exists('name', $parameter)) || $parameter instanceof PhpFunctionParameter;
- }
- /**
- class PhpFunctionParameter extends PhpVariable implements TypeHintedElementInterface
- {
- use TypeHintedElementTrait;
- public function __construct(string $name, $value = null, $type = null)
- {
- parent::__construct($name, $value);
- $this->setType($type);
- }
- class PhpFunctionParameter extends PhpVariable implements TypeHintedElementInterface
- {
- use TypeHintedElementTrait;
- public function __construct(string $name, $value = null, $type = null)
- {
- parent::__construct($name, $value);
- $this->setType($type);
- }
- public function endsWithSemicolon(): bool
- {
- return false;
- }
- protected function getAnyValue($value): string
- {
- if (is_array($value)) {
- return str_replace([self::BREAK_LINE_CHAR, ' '], '', parent::getAnyValue($value));
- }
- class PhpProperty extends PhpVariable implements AccessRestrictedElementInterface, TypeHintedElementInterface
- {
- use AccessRestrictedElementTrait;
- use TypeHintedElementTrait;
- public function __construct(string $name, $value = null, string $access = self::ACCESS_PUBLIC, $type = null)
- {
- parent::__construct($name, $value);
- $this->setType($type);
- $this->setAccess($access);
- }
- class PhpProperty extends PhpVariable implements AccessRestrictedElementInterface, TypeHintedElementInterface
- {
- use AccessRestrictedElementTrait;
- use TypeHintedElementTrait;
- public function __construct(string $name, $value = null, string $access = self::ACCESS_PUBLIC, $type = null)
- {
- parent::__construct($name, $value);
- $this->setType($type);
- $this->setAccess($access);
- }
- use WsdlToPhp\PhpGenerator\Element\PhpMethod as PhpMethodElement;
- use WsdlToPhp\PhpGenerator\Element\PhpProperty as PhpPropertyElement;
- class PhpClass extends AbstractComponent
- {
- public function __construct(string $name, bool $abstract = false, ?string $extends = null, array $interfaces = [])
- {
- $this->setMainElement(new PhpClassElement($name, $abstract, $extends, $interfaces));
- }
- public function addMethodElement(PhpMethodElement $method): self
- $this->mainElement->addChild($method);
- return $this;
- }
- public function addMethod(string $name, array $parameters = [], ?string $returnType = null, string $access = PhpMethodElement::ACCESS_PUBLIC, bool $abstract = false, bool $static = false, bool $final = false, bool $hasBody = true): self
- {
- return $this->addMethodElement(new PhpMethodElement($name, $parameters, $returnType, $access, $abstract, $static, $final, $hasBody));
- }
- public function addPropertyElement(PhpPropertyElement $property): self
- $this->mainElement->addChild($property);
- return $this;
- }
- public function addProperty(string $name, $value = null, string $access = PhpPropertyElement::ACCESS_PUBLIC, $type = null): self
- {
- return $this->addPropertyElement(new PhpPropertyElement($name, $value, $access, $type));
- }
- }
- $this->mainElement->addChild($property);
- return $this;
- }
- public function addProperty(string $name, $value = null, string $access = PhpPropertyElement::ACCESS_PUBLIC, $type = null): self
- {
- return $this->addPropertyElement(new PhpPropertyElement($name, $value, $access, $type));
- }
- }
- use WsdlToPhp\PhpGenerator\Element\PhpMethod as PhpMethodElement;
- use WsdlToPhp\PhpGenerator\Element\PhpProperty as PhpPropertyElement;
- class PhpInterface extends PhpClass
- {
- public function __construct(string $name, bool $abstract = false, ?string $extends = null, array $interfaces = [])
- {
- $this->setMainElement(new PhpInterfaceElement($name, $abstract, $extends, $interfaces));
- }
- public function addMethodElement(PhpMethodElement $method): self
- parent::addMethodElement($method);
- return $this;
- }
- public function addMethod(string $name, array $parameters = [], ?string $returnType = null, string $access = PhpMethodElement::ACCESS_PUBLIC, bool $abstract = false, bool $static = false, bool $final = false, bool $hasBody = true): self
- {
- return $this->addMethodElement(new PhpMethodElement($name, $parameters, $returnType, $access, $abstract, $static, $final, false));
- }
- public function addPropertyElement(PhpPropertyElement $property): self
- public function addPropertyElement(PhpPropertyElement $property): self
- {
- return $this;
- }
- public function addProperty(string $name, $value = null, string $access = PhpPropertyElement::ACCESS_PUBLIC, $type = null): self
- {
- return $this;
- }
- }
- public function addPropertyElement(PhpPropertyElement $property): self
- {
- return $this;
- }
- public function addProperty(string $name, $value = null, string $access = PhpPropertyElement::ACCESS_PUBLIC, $type = null): self
- {
- return $this;
- }
- }
- }
- /**
- * @param array|PhpAnnotationBlockElement|string $annotations
- */
- public function addAnnotationBlock($annotations): self
- {
- return $this->addAnnotationBlockElement(new PhpAnnotationBlockElement(is_array($annotations) ? $annotations : [
- $annotations,
- ]));
- }
- $this->mainElement->addChild($variable);
- return $this;
- }
- public function addVariable(string $name, $value = null): self
- {
- return $this->addVariableElement(new PhpVariableElement($name, $value));
- }
- public function addFunctionElement(PhpFunctionElement $function): self
- $this->mainElement->addChild($function);
- return $this;
- }
- public function addFunction(string $name, array $parameters = []): self
- {
- return $this->addFunctionElement(new PhpFunctionElement($name, $parameters));
- }
- public function addUse(string $use, ?string $as = null, bool $last = false): self
- $this->mainElement->addChild(sprintf('%s%s', self::BREAK_LINE_CHAR, $phpDeclare->toString()));
- return $this;
- }
- public function setDeclare(string $name, $value): self
- {
- return $this->setDeclareElement(new PhpDeclare($name, $value));
- }
- public function setNamespace(string $namespace): self
- }
- return 1 === preg_match($pattern, (string) $name);
- }
- public static function stringIsValid($string, bool $checkName = true, bool $allowBackslash = false): bool
- {
- return is_string($string) && !empty($string) && (!$checkName || static::nameIsValid($string, $allowBackslash));
- }
- public static function objectIsValid($object, ?string $checkClass = null): bool
- public static function stringIsValid($string, bool $checkName = true, bool $allowBackslash = false): bool
- {
- return is_string($string) && !empty($string) && (!$checkName || static::nameIsValid($string, $allowBackslash));
- }
- public static function objectIsValid($object, ?string $checkClass = null): bool
- {
- return is_object($object) && (is_null($checkClass) || get_class($object) === $checkClass);
- }
- public function toString(?int $indentation = null): string
- public function getPhpName(): string
- {
- return sprintf('%s', $this->getName());
- }
- public function addChild($child): self
- {
- if (!$this->childIsValid($child)) {
- $types = $this->getChildrenTypes();
- if (empty($types)) {
- throw new \InvalidArgumentException('This element does not accept any child element');
- final public function getCalledClass(): string
- {
- return substr(static::class, strrpos(static::class, '\\') + 1);
- }
- protected function getChildContent($child, ?int $indentation = null): string
- {
- $content = '';
- if (is_string($child)) {
- $content = $this->getIndentedString($child, $indentation);
- } elseif ($child instanceof AbstractElement) {
- }
- return $content;
- }
- protected function childIsValid($child): bool
- {
- $valid = false;
- $authorizedTypes = $this->getChildrenTypes();
- if (!empty($authorizedTypes)) {
- foreach ($authorizedTypes as $authorizedType) {
- }
- return null;
- }
- private static function cleanArrayToString(array $array): array
- {
- $newArray = [];
- foreach ($array as $line) {
- if (is_null($line)) {
- continue;
- /**
- * Use this constant as value to ensure element has not assigned value.
- */
- public const NO_VALUE = '##NO_VALUE##';
- public function setValue($value): AbstractElement;
- public function getValue();
- public function hasValue(): bool;
- use AccessRestrictedElementTrait;
- use AssignedValueElementTrait;
- protected ?PhpClass $class;
- public function __construct(string $name, $value = null, ?PhpClass $class = null)
- {
- parent::__construct($name);
- $this->setValue($value);
- $this->setClass($class);
- }
- PhpMethod::class,
- PhpConstant::class,
- ];
- }
- public function addChild($child): AbstractElement
- {
- if ($child instanceof PhpMethod) {
- $child->setHasBody(false);
- }
- class PhpVariable extends AbstractElement implements AssignedValueElementInterface
- {
- use AssignedValueElementTrait;
- public function __construct(string $name, $value = null)
- {
- parent::__construct($name);
- $this->setValue($value);
- }
- self::TYPE_FLOAT,
- self::TYPE_OBJECT,
- self::TYPE_STRING,
- ];
- public function setType($type): AbstractElement;
- public function getType();
- public static function typeIsValid(?string $access): bool;
- }
Your project should use return types 9
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.missing_return_typehint
- $this->value = $value;
- return $this;
- }
- public function getValue()
- {
- return $this->value;
- }
- public function hasValue(): bool
- $this->value = $value;
- return $this;
- }
- public function getValue()
- {
- return $this->value;
- }
- public function hasValue(): bool
- $this->parameters = static::transformParameters($parameters);
- return $this;
- }
- public static function transformParameters(array $parameters): array
- {
- $finalParameters = [];
- foreach ($parameters as $parameter) {
- $finalParameters[] = static::transformParameter($parameter);
- }
- }
- return null;
- }
- private static function cleanArrayToString(array $array): array
- {
- $newArray = [];
- foreach ($array as $line) {
- if (is_null($line)) {
- continue;
- */
- public const NO_VALUE = '##NO_VALUE##';
- public function setValue($value): AbstractElement;
- public function getValue();
- public function hasValue(): bool;
- public function getPhpValue(): ?string;
- /**
- * Always return null to avoid having a literal string instead of quoted string.
- *
- * @param mixed $value
- */
- protected function getScalarValue($value)
- {
- return null;
- }
- }
- self::TYPE_STRING,
- ];
- public function setType($type): AbstractElement;
- public function getType();
- public static function typeIsValid(?string $access): bool;
- }
- public function toString(?int $indentation = null): string;
- /**
- * stores current indentation.
- */
- public function setIndentation(int $indentation);
- /**
- * Returns current indentation.
- */
- public function getIndentation(): int;
- public function getMaxLength(): int
- {
- return $this->maxLength;
- }
- protected function getPhpContent(): array
- {
- $fullContent = trim(sprintf('%s %s', $this->getPhpName(), $this->getContent()));
- $content = [
- $fullContent,
- ];
Your project must not contain invalid instantiations 6
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_instantiation
- }
- if (is_string($annotation)) {
- return new PhpAnnotation(PhpAnnotation::NO_NAME, $annotation);
- }
- if (is_array($annotation) && array_key_exists('content', $annotation)) {
- return new PhpAnnotation(array_key_exists('name', $annotation) ? $annotation['name'] : PhpAnnotation::NO_NAME, $annotation['content']);
- }
- throw new \InvalidArgumentException(sprintf('Annotation parameter "%s" is invalid', gettype($annotation)));
- }
- }
- if (is_string($annotation)) {
- return new PhpAnnotation(PhpAnnotation::NO_NAME, $annotation);
- }
- if (is_array($annotation) && array_key_exists('content', $annotation)) {
- return new PhpAnnotation(array_key_exists('name', $annotation) ? $annotation['name'] : PhpAnnotation::NO_NAME, $annotation['content']);
- }
- throw new \InvalidArgumentException(sprintf('Annotation parameter "%s" is invalid', gettype($annotation)));
- }
- {
- if ($parameter instanceof PhpFunctionParameter) {
- return $parameter;
- }
- if (is_array($parameter)) {
- return new PhpFunctionParameter($parameter['name'], array_key_exists('value', $parameter) ? $parameter['value'] : null, array_key_exists('type', $parameter) ? $parameter['type'] : null);
- }
- return new PhpFunctionParameter($parameter, PhpFunctionParameter::NO_VALUE);
- }
- }
- if (is_array($parameter)) {
- return new PhpFunctionParameter($parameter['name'], array_key_exists('value', $parameter) ? $parameter['value'] : null, array_key_exists('type', $parameter) ? $parameter['type'] : null);
- }
- return new PhpFunctionParameter($parameter, PhpFunctionParameter::NO_VALUE);
- }
- public static function parametersAreValid(array $parameters): bool
- {
- $valid = true;
- return $this;
- }
- public function addMethod(string $name, array $parameters = [], ?string $returnType = null, string $access = PhpMethodElement::ACCESS_PUBLIC, bool $abstract = false, bool $static = false, bool $final = false, bool $hasBody = true): self
- {
- return $this->addMethodElement(new PhpMethodElement($name, $parameters, $returnType, $access, $abstract, $static, $final, $hasBody));
- }
- public function addPropertyElement(PhpPropertyElement $property): self
- {
- $this->mainElement->addChild($property);
- return $this;
- }
- public function addMethod(string $name, array $parameters = [], ?string $returnType = null, string $access = PhpMethodElement::ACCESS_PUBLIC, bool $abstract = false, bool $static = false, bool $final = false, bool $hasBody = true): self
- {
- return $this->addMethodElement(new PhpMethodElement($name, $parameters, $returnType, $access, $abstract, $static, $final, false));
- }
- public function addPropertyElement(PhpPropertyElement $property): self
- {
- return $this;
Your project gitignore file should not contain user-specific files
- Read doc
- Productivity
- Minor
More information: https://insight.symfony.com/what-we-analyse/git.user_specific_ignored_file
- vendor/
- composer.lock
- phpunit.xml
- .phpunit.result.cache
- .idea/
Text files should end with a valid new line character.
- Read doc
- Productivity
- Info
More information: https://insight.symfony.com/what-we-analyse/missing_e_o_l
- up:
- $(DOCKER_COMPOSE) up -d
- update:
- $(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) $(COMPOSER) update