LinkObject   A
last analyzed

Complexity

Total Complexity 23

Size/Duplication

Total Lines 125
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 86.96%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 125
loc 125
ccs 40
cts 46
cp 0.8696
rs 10
wmc 23
lcom 1
cbo 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
B symlink() 13 13 5
B hardlink() 13 13 6
A lstat() 7 7 2
A lstatDiff() 7 7 2
A readlink() 8 8 2
A lchgrp() 8 8 2
A lchown() 8 8 2
A linkinfo() 8 8 2

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
 * Created by:  Marko Kungla @ OkramLabs on Aug 6, 2012 - 9:31:36
4
 * Contact:     [email protected] - https://okramlabs.com
5
 * @copyright   2015 OkramLabs - https://okramlabs.com
6
 * @license     MIT
7
 *
8
 * Package name:libhowi-filesystem
9
 * @category	HOWI3
10
 * @package		libhowi
11
 * @subpackage	filesystem
12
 * 
13
 * Lang:      PHP
14
 * Encoding:  UTF-8
15
 * File:      LinkTrait.inc
16
 * @link      https://
17
 ********************************************************************
18
 * Contributors:
19
 * @author Marko Kungla <[email protected]>
20
 *           Github: https://github.com/mkungla
21
 ********************************************************************
22
 * Comments:
23
 */
24
namespace HOWI3\libhowi\Filesystem\php7\Objects;
25
26
use HOWI3\libhowi\Filesystem\php7\TraitForSharedMethods;
27
use HOWI3\libhowi\Filesystem\Commons\ObjectInterfaces\LinkInterface;
28
29 View Code Duplication
class LinkObject implements LinkInterface
0 ignored issues
show
Duplication introduced by
This class 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...
30
{
31
    
32
    use TraitForSharedMethods;
33
34
    /**
35
     *
36
     * {@inheritDoc}
37
     *
38
     */
39 1
    public function symlink($target = false, $link = false)
40
    {
41 1
        if (empty($target) || empty($link))
42
            return false;
43
        
44 1
        $target = $this->makeAbsolute($target);
45 1
        $link = $this->makeAbsolute($link);
46
        
47 1
        if (! file_exists($target) || file_exists($link))
48
            return false;
49
        
50 1
        return symlink($target, $link);
51
    }
52
53
    /**
54
     *
55
     * {@inheritDoc}
56
     *
57
     */
58 1
    public function hardlink($target = false, $link = false)
59
    {
60 1
        if (empty($target) || empty($link))
61
            return false;
62
        
63 1
        $target = $this->makeAbsolute($target);
64 1
        $link = $this->makeAbsolute($link);
65
        
66 1
        if (! file_exists($target) || is_dir($target) || file_exists($link))
67 1
            return false;
68
        
69 1
        return link($target, $link);
70
    }
71
72
    /**
73
     *
74
     * {@inheritDoc}
75
     *
76
     */
77 1
    public function lstat($link = false)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
78
    {
79 1
        if (empty($link))
80
            return false;
81 1
        $link = $this->makeAbsolute($link);
82 1
        return @lstat($link);
83
    }
84
85
    /**
86
     *
87
     * {@inheritDoc}
88
     *
89
     */
90 1
    public function lstatDiff($link = false)
91
    {
92 1
        if (empty($link))
93
            return false;
94 1
        $link = $this->makeAbsolute($link);
95 1
        return array_diff(stat($link), lstat($link));
96
    }
97
98
    /**
99
     *
100
     * {@inheritDoc}
101
     *
102
     */
103 1
    public function readlink($link = false)
104
    {
105 1
        if (empty($link))
106
            return false;
107
        
108 1
        $link = $this->makeAbsolute($link);
109 1
        return readlink($link);
110
    }
111
112
    /**
113
     *
114
     * {@inheritDoc}
115
     *
116
     */
117 1
    public function lchgrp($link = false, $group = false)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
118
    {
119 1
        if (empty($link))
120 1
            return false;
121
        
122 1
        $link = $this->makeAbsolute($link);
123 1
        return @lchgrp($link, $group);
124
    }
125
126
    /**
127
     *
128
     * {@inheritDoc}
129
     *
130
     */
131 1
    public function lchown($link = false, $group = false)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
132
    {
133 1
        if (empty($link))
134 1
            return false;
135
        
136 1
        $link = $this->makeAbsolute($link);
137 1
        return @lchown($link, $group);
138
    }
139
140
    /**
141
     *
142
     * {@inheritDoc}
143
     *
144
     */
145 1
    public function linkinfo($link = false)
146
    {
147 1
        if (empty($link))
148 1
            return false;
149
        
150 1
        $link = $this->makeAbsolute($link);
151 1
        return linkinfo($link);
152
    }
153
}
154