Path   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 30 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 0
cbo 1
dl 6
loc 20
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 12 3

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 the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Cubiche\Domain\Web;
13
14
use Cubiche\Domain\System\StringLiteral;
15
16
/**
17
 * Path class.
18
 *
19
 * @author Ivannis Suárez Jerez <[email protected]>
20
 */
21
class Path extends StringLiteral
22
{
23
    /**
24
     * @param string $value
25
     *
26
     * @throws \InvalidArgumentException
27
     */
28
    public function __construct($value)
29
    {
30
        $filteredValue = parse_url($value, PHP_URL_PATH);
31 View Code Duplication
        if ($filteredValue === null || strlen($filteredValue) != strlen($value)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
32
            throw new \InvalidArgumentException(sprintf(
33
                'Argument "%s" is invalid. Allowed types for argument are "url path".',
34
                $value
35
            ));
36
        }
37
38
        parent::__construct($filteredValue);
0 ignored issues
show
Security Bug introduced by
It seems like $filteredValue defined by parse_url($value, PHP_URL_PATH) on line 30 can also be of type false; however, Cubiche\Domain\System\StringLiteral::__construct() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
39
    }
40
}
41