Completed
Push — master ( f7eb77...bdcf7d )
by Tomáš
03:24
created

Ruleset   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 16.66%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 10
lcom 0
cbo 0
dl 0
loc 59
ccs 3
cts 18
cp 0.1666
rs 10
c 2
b 0
f 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A decorateSniffsWithCustomRules() 0 17 4
B setSniffProperty() 0 20 5
1
<?php
2
3
/*
4
 * This file is part of Symplify
5
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
6
 */
7
8
namespace Symplify\PHP7_CodeSniffer\Ruleset;
9
10
use PHP_CodeSniffer\Sniffs\Sniff;
11
12
final class Ruleset
13
{
14
    /**
15
     * @var RulesetBuilder
16
     */
17
    private $rulesetBuilder;
18
19 1
    public function __construct(RulesetBuilder $rulesetBuilder)
20
    {
21 1
        $this->rulesetBuilder = $rulesetBuilder;
22 1
    }
23
24
    /**
25
     * @param array|Sniff[] $sniffs
26
     */
27
    public function decorateSniffsWithCustomRules(array $sniffs, array $ruleset)
0 ignored issues
show
Unused Code introduced by
The parameter $sniffs is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
28
    {
29
        dump($ruleset);
30
        die;
0 ignored issues
show
Coding Style Compatibility introduced by
The method decorateSniffsWithCustomRules() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
31
        // todo: put to SniffDispatcher on sniff loading?
32
        //        $ruleset = $this->rulesetBuilder->getRuleset();
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
33
34
        foreach ($sniffs as $sniffCode => $sniffObject) {
0 ignored issues
show
Unused Code introduced by
// todo: put to SniffDis...$name, $value); } } does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
35
            if (!isset($ruleset[$sniffCode]['properties'])) {
36
                continue;
37
            }
38
39
            foreach ($ruleset[$sniffCode]['properties'] as $name => $value) {
40
                $this->setSniffProperty($sniffCode, $name, $value);
41
            }
42
        }
43
    }
44
45
    /**
46
     * @param string $sniffCode
47
     * @param string $name
48
     * @param string|array $value
49
     */
50
    private function setSniffProperty(string $sniffCode, string $name, $value)
51
    {
52
        if (isset($sniffs[$sniffCode]) === false) {
0 ignored issues
show
Bug introduced by
The variable $sniffs seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
53
            return;
54
        }
55
56
        $name = trim($name);
57
        if (is_string($value)) {
58
            $value = trim($value);
59
        }
60
61
        // Special case for booleans.
62
        if ($value === 'true') {
63
            $value = true;
64
        } elseif ($value === 'false') {
65
            $value = false;
66
        }
67
68
        $sniffs[$sniffCode]->$name = $value;
0 ignored issues
show
Bug introduced by
The variable $sniffs does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
69
    }
70
}
71