Completed
Push — master ( 1f3396...4932db )
by Cristiano
02:20
created

CheckerPart::isSingular()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
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
11
namespace phootwork\lang\parts;
12
13
use phootwork\lang\inflector\Inflector;
14
use phootwork\lang\inflector\InflectorInterface;
15
16
trait CheckerPart {
17
18
	/**
19
	 * Checks if the string is empty
20
	 *
21
	 * @return boolean
22
	 */
23 4
	public function isEmpty(): bool {
24 4
		return empty($this->string);
25
	}
26
27
	/**
28
	 * Check if the string contains only alphanumeric characters.
29
	 *
30
	 * @return boolean
31
	 */
32 1
	public function isAlphanumeric(): bool {
33 1
		return ctype_alnum($this->string);
34
	}
35
36
	/**
37
	 * Check if the string contains only alphanumeric characters.
38
	 *
39
	 * @return boolean
40
	 */
41 1
	public function isAlphabetic(): bool {
42 1
		return ctype_alpha($this->string);
43
	}
44
45
	/**
46
	 * Check if the string contains only numeric characters.
47
	 *
48
	 * @return boolean
49
	 */
50 1
	public function isNumeric(): bool {
51 1
		return ctype_digit($this->string);
52
	}
53
54
	/**
55
	 * Check if the string contains only characters which are not whitespace or an alphanumeric.
56
	 *
57
	 * @return boolean
58
	 */
59 1
	public function isPunctuation(): bool {
60 1
		return ctype_punct($this->string);
61
	}
62
63
	/**
64
	 * Check if the string contains only space characters.
65
	 *
66
	 * @return boolean
67
	 */
68 1
	public function isSpace(): bool {
69 1
		return ctype_space($this->string);
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 boolean
84
	 */
85 1
	public function isLowerCase(): bool {
86 1
		return ctype_lower($this->string);
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 boolean
101
	 */
102 1
	public function isUpperCase(): bool {
103 1
		return ctype_upper($this->string);
104
	}
105
106
	/**
107
	 * Check if a string is singular form.
108
	 *
109
	 * @param InflectorInterface $pluralizer
110
	 *        	A custom pluralizer. Default is the Inflector
111
	 * @return boolean
112
	 */
113 1
	public function isSingular(?InflectorInterface $pluralizer = null): bool {
114 1
		$pluralizer = $pluralizer ?? new Inflector();
115
116 1
		return $pluralizer->isSingular($this->string);
117
	}
118
119
	/**
120
	 * Check if a string is plural form.
121
	 *
122
	 * @param InflectorInterface $pluralizer
123
	 *        	A custom pluralizer. Default is the Inflector
124
	 * @return boolean
125
	 */
126 1
	public function isPlural(?InflectorInterface $pluralizer = null): bool {
127 1
		$pluralizer = $pluralizer ?? new Inflector();
128
129 1
		return $pluralizer->isPlural($this->string);
130
	}
131
}
132