Completed
Push — master ( 1d9387...a47b74 )
by Garrett
08:57
created

AnyStrObj::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace StringObject;
4
5
abstract class AnyStrObj
6
{
7
    protected $raw;
8
9
    public function __construct($thing)
10
    {
11
        self::testStringableObject($thing);
12
        $this->raw = (string) $thing;
13
    }
14
15
    /**
16
     * @return mixed
17
     */
18
    public function __get($name)
19
    {
20
        return $this->$name;
21
    }
22
23
    /**
24
     * @return string
25
     */
26
    public function __toString()
27
    {
28
        return $this->raw;
29
    }
30
31
    public abstract function compareTo($str, $mode = self::NORMAL, $length = 1);
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
32
33
    public function asciify($removeUnsupported = true)
34
    {
35
        $str = $this->raw;
36
        foreach (self::$asciimap as $key => $value) {
37
            $str = \str_replace($value, $key, $str);
38
        }
39
        if ($removeUnsupported) {
40
            $str = \preg_replace('/[^\x20-\x7E]/u', '', $str);
41
        }
42
        return new self($str);
43
    }
44
45
    public abstract function escape($mode = self::NORMAL, $charlist = '');
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
46
47
    public abstract function nextToken($delim);
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
48
49
    public abstract function remove($str, $mode = self::NORMAL);
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
50
51
    public abstract function repeat($times);
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
52
53
    /**
54
     * @param string $replace
55
     */
56
    public abstract function replace($search, $replace, $mode = self::NORMAL);
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
57
58
    public abstract function resetToken();
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
59
60
    public abstract function times($times);
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
61
62
    public abstract function translate($search, $replace = '');
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
63
64
    public abstract function trim($mask = " \t\n\r\0\x0B", $mode = self::BOTH_ENDS);
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
65
66
    public abstract function unescape($mode = self::NORMAL);
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
67
68
    public abstract function uuDecode();
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
69
70
    public abstract function uuEncode();
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
71
72
    public function equals($str)
73
    {
74
        self::testStringableObject($str);
75
76
        $str = (string) $str;
77
        return ($str == $this->raw);
78
    }
79
80
    public abstract function isAscii();
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
81
82
    public abstract function isEmpty();
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
83
84
    protected static function testStringableObject($thing)
85
    {
86
        if (\is_object($thing) && !\method_exists($thing, '__toString')) {
87
            throw new \InvalidArgumentException(
88
                'Parameter is an object that does not implement __toString() method'
89
            );
90
        } elseif (\is_array($thing)) {
91
            throw new \InvalidArgumentException('Unsure of how to convert array to string');
92
        }
93
    }
94
}
95