CheckerPart   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 117
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0
wmc 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A isEmpty() 0 2 1
A isPunctuation() 0 2 1
A isUpperCase() 0 2 1
A isAlphanumeric() 0 2 1
A isAlphabetic() 0 2 1
A isNumeric() 0 2 1
A isLowerCase() 0 2 1
A isSpace() 0 2 1
A isPlural() 0 4 1
A isSingular() 0 4 1
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the Phootwork package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 *
7
 * @license MIT License
8
 * @copyright Thomas Gossmann
9
 */
10
namespace phootwork\lang\parts;
11
12
use phootwork\lang\inflector\Inflector;
13
use phootwork\lang\inflector\InflectorInterface;
14
15
trait CheckerPart {
16
	abstract protected function getString(): string;
17
18
	/**
19
	 * Checks if the string is empty
20
	 *
21
	 * @return bool
22
	 */
23 6
	public function isEmpty(): bool {
24 6
		return empty($this->getString());
25
	}
26
27
	/**
28
	 * Check if the string contains only alphanumeric characters.
29
	 *
30
	 * @return bool
31
	 */
32 1
	public function isAlphanumeric(): bool {
33 1
		return ctype_alnum($this->getString());
34
	}
35
36
	/**
37
	 * Check if the string contains only alphanumeric characters.
38
	 *
39
	 * @return bool
40
	 */
41 1
	public function isAlphabetic(): bool {
42 1
		return ctype_alpha($this->getString());
43
	}
44
45
	/**
46
	 * Check if the string contains only numeric characters.
47
	 *
48
	 * @return bool
49
	 */
50 1
	public function isNumeric(): bool {
51 1
		return ctype_digit($this->getString());
52
	}
53
54
	/**
55
	 * Check if the string contains only characters which are not whitespace or an alphanumeric.
56
	 *
57
	 * @return bool
58
	 */
59 1
	public function isPunctuation(): bool {
60 1
		return ctype_punct($this->getString());
61
	}
62
63
	/**
64
	 * Check if the string contains only space characters.
65
	 *
66
	 * @return bool
67
	 */
68 1
	public function isSpace(): bool {
69 1
		return ctype_space($this->getString());
70
	}
71
72
	/**
73
	 * Check if the string contains only lower case characters.
74
	 *
75
	 * Spaces are considered non-lowercase characters, so lowercase strings with multiple words, separated by spaces,
76
	 * return false. E.g.:
77
	 *
78
	 * <code>
79
	 * $text = new Text('lowercase multi words string');<br>
80
	 * var_dump($text->isLowercase()); // false
81
	 * </code>
82
	 *
83
	 * @return bool
84
	 */
85 1
	public function isLowerCase(): bool {
86 1
		return ctype_lower($this->getString());
87
	}
88
89
	/**
90
	 * Check if the string contains only upper case characters.
91
	 *
92
	 * Spaces are considered non-uppercase characters, so uppercase strings with multiple words, separated by spaces,
93
	 * return false. E.g.:
94
	 *
95
	 * <code>
96
	 * $text = new Text('UPPERCASE MULTI WORDS STRING'); <br>
97
	 * var_dump($text->isUppercase()); // false
98
	 * </code>
99
	 *
100
	 * @return bool
101
	 */
102 1
	public function isUpperCase(): bool {
103 1
		return ctype_upper($this->getString());
104
	}
105
106
	/**
107
	 * Check if a string is singular form.
108
	 *
109
	 * @param InflectorInterface|null $pluralizer
110
	 *            A custom pluralizer. Default is the Inflector
111
	 *
112
	 * @return bool
113
	 */
114 1
	public function isSingular(?InflectorInterface $pluralizer = null): bool {
115 1
		$pluralizer = $pluralizer ?? new Inflector();
116
117 1
		return $pluralizer->isSingular($this->getString());
118
	}
119
120
	/**
121
	 * Check if a string is plural form.
122
	 *
123
	 * @param InflectorInterface|null $pluralizer
124
	 *            A custom pluralizer. Default is the Inflector
125
	 *
126
	 * @return bool
127
	 */
128 1
	public function isPlural(?InflectorInterface $pluralizer = null): bool {
129 1
		$pluralizer = $pluralizer ?? new Inflector();
130
131 1
		return $pluralizer->isPlural($this->getString());
132
	}
133
}
134