Skip to content

Commit 44e0cb9

Browse files
committed
Fix small issues in the readme
1 parent eb06659 commit 44e0cb9

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

README.md

+31-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ if ($status->equals(ContractStatus::ACTIVE())) {
5151
}
5252
```
5353

54-
##Installation
54+
## Installation
5555

5656
```bash
5757
$ composer require cuyz/magic-constant
@@ -92,7 +92,8 @@ class Example extends MagicConstant
9292
You can then use the class everywhere:
9393

9494
```php
95-
function hello(Example $example) {
95+
// As a parameter typehint and/or a return typehint
96+
function hello(Example $example): Example {
9697
//
9798
}
9899

@@ -104,54 +105,74 @@ hello(Example::BAR());
104105

105106
## Methods
106107

108+
#### Get an instance value
109+
107110
```php
108111
echo (new Example('foo'))->getValue(); // 'foo'
109112

113+
// You can specify the desired output format
110114
echo (new Example('FIZ'))->getValue(Example::FORMAT_LOWER); // 'fiz'
111115
```
112116

117+
#### Get an instance key
118+
113119
```php
114120
$constant = new Example('b');
115121

116122
echo $constant->getKey(); // 'BAR'
117123
```
118124

125+
#### Get instances with all possible formats
126+
119127
```php
120128
$constant = new Example('fiz');
121129

122130
echo $constant->getAllFormats(); // [new Example('fiz'), new Example('FIZ')]
123131
```
124132

133+
#### Get all possible values for an instance
134+
125135
```php
126136
$constant = new Example('BAR');
127137

128138
echo $constant->getAllValues(); // ['bar', 'BAR', 'b']
129139
```
130140

141+
#### Returns a new instance where the value is from the first format
142+
131143
```php
132144
$constant = new Example('BAR');
133145

134146
echo $constant->normalize(); // new Example('bar')
135147
```
136148

149+
#### Compares instances
150+
137151
```php
138152
(new Example('foo'))->equals(new Exemple('bar')); // false
153+
(new Example('foo'))->equals(null); // false
139154

140155
(new Example('fiz'))->equals(new Exemple('FIZ')); // true
141156
(new Example('b'))->equals(new Exemple('b')); // true
142157
```
143158

159+
#### Returns true if at least one element is equal
160+
144161
```php
145162
$constant = new Example('foo');
146163

147164
$constant->in([new Exemple('bar'), null, 'foo']); // false
148165
$constant->in([new Exemple('foo'), null, 'foo']); // true
149166
```
150167

168+
#### Get all keys for a magic constant class
169+
151170
```php
152171
Example::keys(); // ['FOO', 'BAR', 'FIZ']
153172
```
154173

174+
#### Get an associative array of possible values
175+
155176
```php
156177
Example::values();
157178

@@ -170,6 +191,8 @@ Example::values('/^F(.+)/');
170191
];
171192
```
172193

194+
#### Get all keys and associated values
195+
173196
```php
174197
Example::toArray();
175198

@@ -180,16 +203,22 @@ Example::toArray();
180203
];
181204
```
182205

206+
#### Check if a value is valid
207+
183208
```php
184209
Example::isValidValue('foo'); // true
185210
Example::isValidValue('hello'); // false
186211
```
187212

213+
#### Check if a key is valid
214+
188215
```php
189216
Example::isValidKey('BAR'); // true
190217
Example::isValidKey('HELLO'); // false
191218
```
192219

220+
#### Returns the key of any value
221+
193222
```php
194223
Example::search('foo'); // 'FOO'
195224
Example::search('b'); // 'BAR'

0 commit comments

Comments
 (0)