Passed
Push — master ( 252c51...fbb2a0 )
by dima
06:40
created

TestHelper::getProtectedAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 7
rs 9.4286
cc 1
eloc 5
nc 1
nop 2
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 4 and the first side effect is on line 2.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
$loader = require_once __DIR__.'/../vendor/autoload.php';
3
4
class TestHelper{
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
5
    
6
    /**
7
     * получение защищенного свойства
8
     * @param type $o
0 ignored issues
show
Bug introduced by
There is no parameter named $o. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
9
     * @param type $name
10
     * @return type
11
     */
12
    static public function getProtectedAttribute($obj, $name)
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
13
    {
14
        $reflectionClass = new \ReflectionClass($obj); //создаем reflectionClass
15
        $r = $reflectionClass->getProperty($name); //получаем свойство
16
        $r->setAccessible(true); //делаем открытым
17
        return $r->getValue($obj);
18
    }
19
20
    /**
21
     * Добавление значения в защищенное свойтсво
22
     * @param type $name
23
     * @param type $valued 
0 ignored issues
show
Documentation introduced by
There is no parameter named $valued. Did you maybe mean $value?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
24
     */
25
    private function setValueprotectedProperty($name, $value)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
26
    {
27
        $reflectionClass = new \ReflectionClass($this->object); //создаем reflectionClass
0 ignored issues
show
Bug introduced by
The property object does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
28
        $r = $reflectionClass->getProperty($name); //получаем свойство
29
        $r->setAccessible(true); //делаем открытым
30
        $r->setValue($this->object, $value); //изменяем значение
31
    }    
32
	
33
	static public function callMethod($obj, $name, array $args) {
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
34
        $class = new \ReflectionClass($obj);
35
        $method = $class->getMethod($name);
36
        $method->setAccessible(true);
37
        return $method->invokeArgs($obj, $args);
38
    }	
39
    
40
}
41