Ajde_Component_Css   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 26.23 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 16
loc 61
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A processStatic() 0 6 1
A _init() 0 9 1
B process() 16 41 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
class Ajde_Component_Css extends Ajde_Component_Resource
4
{
5
    public static function processStatic(Ajde_Template_Parser $parser, $attributes)
6
    {
7
        $instance = new self($parser, $attributes);
8
9
        return $instance->process();
10
    }
11
12
    protected function _init()
13
    {
14
        return [
15
            'action'     => 'local',
16
            'filename'   => 'public',
17
            'url'        => 'remote',
18
            'fontFamily' => 'font',
19
        ];
20
    }
21
22
    public function process()
23
    {
24
        switch ($this->_attributeParse()) {
25
            case 'local':
26
                $this->requireResource(
27
                    Ajde_Resource_Local::TYPE_STYLESHEET,
28
                    $this->attributes['action'],
29
                    issetor($this->attributes['format'], null),
30
                    issetor($this->attributes['base'], null),
31
                    issetor($this->attributes['position'], null),
32
                    issetor($this->attributes['arguments'], '')
33
                );
34
                break;
35 View Code Duplication
            case 'public':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
                $this->requirePublicResource(
37
                    Ajde_Resource_Local::TYPE_STYLESHEET,
38
                    $this->attributes['filename'],
39
                    issetor($this->attributes['position'], null),
40
                    issetor($this->attributes['arguments'], '')
41
                );
42
                break;
43 View Code Duplication
            case 'remote':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
                $this->requireRemoteResource(
45
                    Ajde_Resource_Local::TYPE_STYLESHEET,
46
                    $this->attributes['url'],
47
                    issetor($this->attributes['position'], null),
48
                    issetor($this->attributes['arguments'], '')
49
                );
50
                break;
51
            case 'font':
52
                $url = Ajde_Resource_GWebFont::getUrl(
53
                    $this->attributes['fontFamily'],
54
                    issetor($this->attributes['fontWeight'], [400]),
0 ignored issues
show
Documentation introduced by
issetor($this->attribute...ntWeight'], array(400)) is of type null, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
55
                    issetor($this->attributes['fontSubset'], ['latin'])
0 ignored issues
show
Documentation introduced by
issetor($this->attribute...bset'], array('latin')) is of type null, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
56
                );
57
                $resource = new Ajde_Resource_Remote(Ajde_Resource::TYPE_STYLESHEET, $url);
58
                $this->getParser()->getDocument()->addResource($resource,
0 ignored issues
show
Documentation Bug introduced by
The method getDocument does not exist on object<Ajde_Template_Parser>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
59
                    Ajde_Document_Format_Html::RESOURCE_POSITION_TOP);
60
                break;
61
        }
62
    }
63
}
64