CompilerPass   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 3
dl 0
loc 30
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 18 1
1
<?php
2
3
namespace BrainExe\Core\Annotations\Builder;
4
5
use BrainExe\Core\Annotations\Service;
6
use BrainExe\Core\Annotations\CompilerPass as CompilerPassAnnotation;
7
use Exception;
8
use ReflectionClass;
9
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
10
use Symfony\Component\DependencyInjection\Definition;
11
12
class CompilerPass extends ServiceDefinition
13
{
14
15
    /**
16
     * @param ReflectionClass $reflectionClass
17
     * @param Service|CompilerPassAnnotation $annotation
18
     * @param Definition $definition
19
     * @return array
20
     *
21
     * @throws Exception
22
     */
23 1
    public function build(ReflectionClass $reflectionClass, Service $annotation, Definition $definition)
24
    {
25
        /** @var Definition $definition */
26 1
        [$serviceId, $definition] = parent::build($reflectionClass, $annotation, $definition);
0 ignored issues
show
Bug introduced by
The variable $serviceId does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
27
28 1
        $definition->setPublic(false);
29 1
        $this->container->setDefinition($serviceId, $definition);
30
31
        /** @var CompilerPassInterface $compilerPass */
32 1
        $compilerPass = $this->container->get($serviceId);
33 1
        $this->container->addCompilerPass(
34
            $compilerPass,
35 1
            $annotation->type,
0 ignored issues
show
Documentation introduced by
The property type does not exist on object<BrainExe\Core\Annotations\Service>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
36 1
            $annotation->priority
0 ignored issues
show
Documentation introduced by
The property priority does not exist on object<BrainExe\Core\Annotations\Service>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
37
        );
38
39 1
        return [$serviceId, $definition];
40
    }
41
}
42