Completed
Push — master ( 446f2e...32b2c3 )
by Nelson
11:26
created

B::getProperty4()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * PHP: Nelson Martell Library file
4
 *
5
 * Content:
6
 * - Class definition.
7
 *
8
 * Copyright © 2016 Nelson Martell (http://nelson6e65.github.io)
9
 *
10
 * Licensed under The MIT License (MIT)
11
 * For full copyright and license information, please see the LICENSE
12
 * Redistributions of files must retain the above copyright notice.
13
 *
14
 * @copyright 2016 Nelson Martell
15
 * @link      http://nelson6e65.github.io/php_nml/
16
 * @since     v0.6.0
17
 * @license   http://www.opensource.org/licenses/mit-license.php The MIT License (MIT)
18
 * */
19
20
namespace NelsonMartell\Test\DataProviders\ExampleClass;
21
22
class B extends A
23
{
24
    public function __construct()
25
    {
26
        parent::__construct();
27
        unset(
28
            $this->property2,
29
            $this->property4
30
        );
31
    }
32
33
    // This is a wrapper for attribute2
34
    public $property2;
35
36
    /**
37
     * Sets attribute of parent class directly
38
     */
39
    public function setProperty2($value)
40
    {
41
        $this->attribute2 = $value; //This is accesible since is protected
42
    }
43
44
    public $property4;
45
    protected function getProperty4()
46
    {
47
        return $this->attribute4;
48
    }
49
50
    # ERRORS #########################################
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
51
    /**
52
     * Try to make read-only property accesible in this parent class
53
     * @throws \BadMethodCallException
54
     */
55
    protected function setProperty1($value)
56
    {
57
        $this->attribute1 = $value; //This is not accesible since is declared private in A
0 ignored issues
show
Documentation introduced by
The property $attribute1 is declared private in NelsonMartell\Test\DataProviders\ExampleClass\A. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
58
    }
59
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
60