Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#678)
by Henrique
03:25
created

Attribute   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 47
ccs 9
cts 11
cp 0.8182
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getReferenceValue() 0 7 1
A hasReference() 0 4 2
1
<?php
2
3
/*
4
 * This file is part of Respect/Validation.
5
 *
6
 * (c) Alexandre Gomes Gaigalas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the "LICENSE.md"
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Respect\Validation\Rules;
13
14
use ReflectionProperty;
15
use Respect\Validation\Exceptions\ComponentException;
16
use Respect\Validation\Rule;
17
18
/**
19
 * @author Alexandre Gomes Gaigalas <[email protected]>
20
 * @author Henrique Moody <[email protected]>
21
 *
22
 * @since 0.3.9
23
 */
24
final class Attribute extends AbstractRelated
25
{
26
    /**
27
     * Initializes the rule.
28
     *
29
     * @param string $attributeName
30
     * @param Rule   $rule
31
     * @param bool   $mandatory
32
     */
33 1
    public function __construct(string $attributeName, Rule $rule = null, $mandatory = true)
34
    {
35 1
        if ('' === $attributeName) {
36 1
            throw new ComponentException('Attribute name cannot be empty');
37
        }
38
39
        parent::__construct($attributeName, $rule, $mandatory);
40
    }
41
42
    /**
43
     * Get the value of attribute in the object object even when the attribute is private.
44
     *
45
     * @param object $object
46
     * @param string $attributeName
47
     *
48
     * @return mixed
49
     */
50 21
    public function getReferenceValue($object, $attributeName)
51
    {
52 21
        $attributeMirror = new ReflectionProperty($object, $attributeName);
53 21
        $attributeMirror->setAccessible(true);
54
55 21
        return $attributeMirror->getValue($object);
56
    }
57
58
    /**
59
     * Verifies if the input is an object and if it has the attribute.
60
     *
61
     * @param object $object
62
     * @param string $attributeName
63
     *
64
     * @return bool
65
     */
66 48
    public function hasReference($object, $attributeName): bool
67
    {
68 48
        return is_object($object) && property_exists($object, $attributeName);
69
    }
70
}
71