Completed
Push — master ( 8e2401...2738c2 )
by Felix
02:17
created

Str::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Felix\Scraper;
4
5
class Str
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
6
{
7
    private $str = null;
8
    private static $instance = null;
9
    
10 1
    private function __construct($str = '') {
11 1
       $this->set($str);
12 1
    }
13
    
14 1
    public static function clean($str = '') {
15 1
        if (! isset(static::$instance)) {
0 ignored issues
show
Bug introduced by
Since $instance is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $instance to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
16 1
            self::$instance = new Str($str);
17
        }
18
        
19 1
        return self::$instance; 
20
    }
21
22
    /**
23
     * Limpiar la cadena y almacenar.
24
     * 
25
     * @param $str string Cadena de caracteres a limpiar.
26
     * 
27
     * @return void
28
     */
29 1
    private function set($str)
30
    {
31 1
        $str = html_entity_decode($str);
32 1
		$str = str_replace("\xc2\xa0", "", $str);
33 1
        $str = trim($str);
34 1
        $str = preg_replace("!\s+!", " ", $str);
35
36 1
        $this->str = $str;
37 1
    }
38
39
	/**
40
	 * Limpiar una cadena de caracteres.
41
	 * 
42
	 * @param string $str Cadena de caracteres a limpiar. 
0 ignored issues
show
Bug introduced by
There is no parameter named $str. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
43
	 * 
44
	 * @return string
45
	 */
46 1
	public function get()
47
	{
48 1
		return $this->str;
49
	}
50
}