GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 290674...0f9d71 )
by Marius
14:11 queued 07:19
created

ModelA::getPropertyNames()   B

Complexity

Conditions 6
Paths 4

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
eloc 9
nc 4
nop 1
dl 0
loc 15
ccs 9
cts 9
cp 1
crap 6
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package domain
4
 * @subpackage models
5
 * @author marius orcsik <[email protected]>
6
 * @date 09.11.19
7
 */
8
namespace vsc\domain\models;
9
10
use vsc\infrastructure\Base;
11
use vsc\ExceptionUnimplemented;
12
13
abstract class ModelA extends Base implements ModelInterface {
14
	use ArrayAccessTrait;
15
	use CountableTrait;
16
	use IteratorTrait;
17
18
	/**
19
	 * @param string $sIncName
20
	 * @return mixed
21
	 */
22 2
	public function __get($sIncName) {
23
		try {
24 2
			$oProperty = new \ReflectionProperty($this, $sIncName);
25 2
			if (!$oProperty->isPublic()) {
26
				// try for a getter method
27 1
				$sGetterName = 'get' . ucfirst($sIncName);
28 1
				$oGetter = new \ReflectionMethod($this, $sGetterName);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
29
30
				$this->_current = $sIncName; // ?? I wonder if setting the offset to the current read position is the right way
31
				return $oGetter->invoke($this, $sIncName);
32
			} else {
33 1
				$this->_current = $sIncName; // ?? I wonder if setting the offset to the current read position is the right way
34 1
				return $oProperty->getValue($this);
35
			}
36 1
		} catch (\ReflectionException $e) {
37
			// reflection issue
38 1
			return parent::__get($sIncName);
39
		}
40
	}
41
42
	/**
43
	 * @param string $sIncName
44
	 * @param mixed $value
45
	 * @throws ExceptionUnimplemented
46
	 * @throws \ReflectionException
47
	 */
48 1
	public function __set($sIncName, $value) {
49 1
		if (is_null($sIncName)) {
50
			throw new \ReflectionException('Can\'t set a value to a null property on the current object [' . get_class($this) . ']');
51
		}
52
		try {
53 1
			$oProperty = new \ReflectionProperty($this, $sIncName);
54 1
			if (!$oProperty->isPublic()) {
55
				// trying for a setter
56
				$sSetterName = 'set' . ucfirst($sIncName);
57
				$oSetter = new \ReflectionMethod($this, $sSetterName);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
58
59
				$oSetter->invoke($this, $value);
60
			} else {
61 1
				$oProperty->setValue($this, $value);
62
			}
63
64 1
			$this->_current = $sIncName;
65 1
			return;
66
		} catch (\ReflectionException $e) {
67
//			$this->_current = $sIncName;
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% 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
//			$this->$sIncName = $value;
69
		}
70
71
		parent::__set($sIncName, $value);
72
	}
73
74 10
	public function __construct() {
75 10
		$this->rewind();
76 10
	}
77
78
	/**
79
	 * @param bool $bAll
80
	 * @return array
81
	 */
82 11
	protected function getPropertyNames($bAll = false) {
83 11
		$aRet = array();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
84 11
		$oMirror = new \ReflectionObject($this);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
85 11
		$aProperties = $oMirror->getProperties();
86
87
		/* @var $oProperty \ReflectionProperty */
88 11
		foreach ($aProperties as $oProperty) {
89
			// skip locally defined properties
90 11
			if ($oProperty->getDeclaringClass()->getName() == ModelA::class) { continue; }
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
introduced by
Consider using $oProperty->class. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
91 11
			if ($bAll || (!$bAll && $oProperty->isPublic())) {
92 11
				$aRet[] = $oProperty->getName();
93
			}
94
		}
95 11
		return $aRet;
96
	}
97
98
	/**
99
	 * @param bool $bIncludeProtected
100
	 * @return array
101
	 */
102 2
	protected function getProperties($bIncludeProtected = false) {
103 2
		$aRet = array();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
104 2
		$oMirror = new \ReflectionObject($this);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
105 2
		$aProperties = $oMirror->getProperties();
106
107
		/* @var $oProperty \ReflectionProperty */
108 2
		foreach ($aProperties as $oProperty) {
109 2
			$sName = $oProperty->getName();
110 2
			if ($oProperty->isPublic()) {
111 2
				$aRet[$sName] = $oProperty->getValue($this);
112 2
			} elseif ($bIncludeProtected) {
113 1
				$oProperty->setAccessible(true);
114 2
				$aRet[$sName] = $oProperty->getValue($this);
115
			}
116
		}
117 2
		return $aRet;
118
	}
119
120
	/**
121
	 * recursively transform all properties into arrays
122
	 */
123 1
	public function toArray() {
124 1
		$aRet = array();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
125 1
		$aProperties = $this->getProperties();
126 1
		foreach ($aProperties as $sName => $oProperty) {
127 1
			if (ModelA::isValid($oProperty)) {
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
128
				/* @var ModelA $oProperty */
129
				$aRet[$sName] = $oProperty->toArray();
130 1
			} elseif (is_array($oProperty) || is_scalar($oProperty)) {
131 1
				$aRet[$sName] = $oProperty;
132 1
			} elseif (is_null($oProperty)) {
133 1
				$aRet[$sName] = $oProperty;
134
			} else {
135 1
				$aRet[$sName] = var_export($oProperty, true);
136
			}
137
		}
138
139 1
		return $aRet;
140
	}
141
}
142