GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

InputAbstract::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of gpupo/similarity
5
 * Created by Gilmar Pupo <[email protected]>
6
 * For the information of copyright and license you should read the file
7
 * LICENSE which is distributed with this source code.
8
 * Para a informação dos direitos autorais e de licença você deve ler o arquivo
9
 * LICENSE que é distribuído com este código-fonte.
10
 * Para obtener la información de los derechos de autor y la licencia debe leer
11
 * el archivo LICENSE que se distribuye con el código fuente.
12
 * For more information, see <https://www.gpupo.com/>.
13
 */
14
15
namespace Gpupo\Similarity\Input;
16
17
abstract class InputAbstract extends \ArrayObject
18
{
19 82 View Code Duplication
    public function __construct($first = null, $second = null,
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...
20
        array $costs = null)
21
    {
22 82
        if (is_array($first)) {
23
            $array = array_combine(['first', 'second', 'costs'], $first);
24
        } else {
25
            $array = [
26 82
                'first'  => $first,
27 82
                'second' => $second,
28 82
                'costs'  => $costs,
29
            ];
30
        }
31 82
        parent::__construct($array, parent::ARRAY_AS_PROPS);
32
33 82
        $this->constructCosts();
34 82
    }
35
36
    public function setFirst($value)
37
    {
38
        return $this->set('first', $value);
39
    }
40
41
    public function setSecond($value)
42
    {
43
        return $this->set('second', $value);
44
    }
45
46 82
    public function setCostsByArray(array $array)
47
    {
48 82
        $this->setCosts(new Costs($array));
49 82
    }
50
51 6
    public function setStopwords(array $array)
52
    {
53 6
        $this->set('stopwords', $array);
54 6
    }
55
56 39
    public function getStopwords()
57
    {
58 39
        return $this->get('stopwords');
59
    }
60
61 82
    protected function constructCosts()
62
    {
63 82
        $defaultCosts = [1, 0, 1];
64
65 82
        return $this->setCostsByArray(($this->costs) ? $this->costs : $defaultCosts);
0 ignored issues
show
Bug introduced by
The property costs does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
66
    }
67
68 82
    public function setCosts($value)
69
    {
70 82
        return $this->set('costs', $value);
71
    }
72
73 82
    protected function set($key, $value)
74
    {
75 82
        $this->$key = $value;
76 82
    }
77
78 82
    protected function get($key)
79
    {
80 82
        if ($this->offsetExists($key)) {
81 82
            return $this->$key;
82
        }
83 33
    }
84
}
85