ToBeMode   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 30.19 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 4
c 4
b 0
f 2
lcom 1
cbo 1
dl 16
loc 53
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A match() 0 9 1
A reportFailed() 8 8 1
A reportNegativeFailed() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * This file is part of expect-filesystem package.
5
 *
6
 * (c) Noritaka Horio <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
namespace expect\filesystem\matcher;
12
13
use expect\FailedMessage;
14
use expect\matcher\ReportableMatcher;
15
use SplFileInfo;
16
17
/**
18
 * Verify a file permissions
19
 *
20
 * <code>
21
 * $matcher = new ToBeMode(644);
22
 * $matcher->match('/path/to/file');
23
 * </code>
24
 *
25
 * @author Noritaka Horio <[email protected]>
26
 */
27
final class ToBeMode implements ReportableMatcher
28
{
29
    /**
30
     * @var string
31
     */
32
    private $actual;
33
34
    /**
35
     * @var int
36
     */
37
    private $expected;
38
39
    private $actualPermission;
40
41
    public function __construct($expected)
42
    {
43
        $this->expected = $expected;
44
    }
45
46
    public function match($actual)
47
    {
48
        $this->actual = $actual;
49
50
        $value = substr(sprintf('%o', fileperms($this->actual)), -4); //Example: 100444
51
        $this->actualPermission = intval($value, 8);
52
53
        return $this->actualPermission === $this->expected;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 View Code Duplication
    public function reportFailed(FailedMessage $message)
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...
60
    {
61
        $message->appendText('Expected ')
62
            ->appendValue($this->actual)
63
            ->appendText(' to be ')
64
            ->appendText('0' . decoct($this->expected))
65
            ->appendText(' mode');
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71 View Code Duplication
    public function reportNegativeFailed(FailedMessage $message)
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...
72
    {
73
        $message->appendText('Expected ')
74
            ->appendValue($this->actual)
75
            ->appendText(' not to be ')
76
            ->appendText('0' . decoct($this->expected))
77
            ->appendText(' mode');
78
    }
79
}
80