Completed
Push — develop ( 168e99...0122be )
by
unknown
18:37 queued 07:11
created

AbstractEntity::__set()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 5

Duplication

Lines 16
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 16
loc 16
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 */
9
10
/** Core Entitys */
11
namespace Core\Entity;
12
13
use Core\Entity\Exception\OutOfBoundsException;
14
15
/**
16
 * Concrete implementation of \Core\Entity\EntityInterface.
17
 *
18
 * Provides some magic function for accessing properties
19
 * as class members, mirroring these calls to the
20
 * getter and setter methods.
21
 *
22
 */
23
abstract class AbstractEntity implements EntityInterface
24
{
25
    use EntityTrait;
26
27
    /**
28
     * Sets a property through the setter method.
29
     *
30
     * An exception is raised, when no setter method exists.
31
     *
32
     * @deprecated since 0.25 Use setter method directly.
33
     * @param string $property
34
     * @param mixed $value
35
     * @return mixed
36
     * @throws OutOfBoundsException
37
     */
38 View Code Duplication
    public function __set($property, $value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
39
    {
40
//        trigger_error(
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
41
//            sprintf(
42
//                'Accessing entity properties is deprecated. Use setter method instead. ( Tried to access "%s" on %s )',
43
//                $property, get_class($this)
44
//            ),
45
//            E_USER_DEPRECATED
46
//        );
47
        $method = "set$property";
48
        if (method_exists($this, $method)) {
49
            return $this->$method($value);
50
        }
51
        
52
        throw new OutOfBoundsException("'$property' is not a valid property of '" . get_class($this). "'");
53
    }
54
    
55
    /**
56
     * Gets a property through the getter method.
57
     *
58
     * An exception is raised, when no getter method exists.
59
     *
60
     * @deprecated since 0.25 use getter method directly.
61
     * @param string $property
62
     * @return mixed
63
     * @throws OutOfBoundsException
64
     */
65 View Code Duplication
    public function __get($property)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
66
    {
67
//        $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
68
//        trigger_error(
69
//            sprintf(
70
//                'Accessing entity properties is deprecated. Use getter method instead. ( Tried to access "%s" on %s in %s on line %s )',
71
//                $property, get_class($this), $trace[0]['file'], $trace[0]['line']
72
//            ),
73
//            E_USER_DEPRECATED
74
//        );
75
        $method = "get$property";
76
        if (method_exists($this, $method)) {
77
            return $this->$method();
78
        }
79
        throw new OutOfBoundsException("'$property' is not a valid property of '" . get_class($this) . "'");
80
    }
81
    
82
    /**
83
     * Checks if a property exists and has a non-empty value.
84
     *
85
     * If the property is an array, the check will return, if this
86
     * array has items or not.
87
     *
88
     * @deprecated since 0.25 Use {@link notEmpty()}
89
     * @param string $property
90
     * @return boolean
91
     */
92
    public function __isset($property)
0 ignored issues
show
Coding Style introduced by
function __isset() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
93
    {
94
//        trigger_error(
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
95
//            sprintf(
96
//                'Using isset() with entity properties is deprecated. Use %s::notEmpty("%s") instead.',
97
//                get_class($this), $property
98
//            ),
99
//            E_USER_DEPRECATED
100
//        );
101
        return $this->notEmpty($property);
102
    }
103
}
104