@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * @link http://api.prototypejs.org/language/Enumerable/ |
17 | 17 | */ |
18 | -trait Enumerable{ |
|
18 | +trait Enumerable { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @var array |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * |
46 | 46 | * @return $this |
47 | 47 | */ |
48 | - public function __each($callback){ |
|
48 | + public function __each($callback) { |
|
49 | 49 | $this->__map($callback); |
50 | 50 | |
51 | 51 | return $this; |
@@ -62,13 +62,13 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function __map($callback):array { |
64 | 64 | |
65 | - if(!is_callable($callback)){ |
|
65 | + if (!is_callable($callback)) { |
|
66 | 66 | throw new TraitException('invalid callback'); |
67 | 67 | } |
68 | 68 | |
69 | 69 | $return = []; |
70 | 70 | |
71 | - foreach($this->array as $index => $element){ |
|
71 | + foreach ($this->array as $index => $element) { |
|
72 | 72 | $return[$index] = call_user_func_array($callback, [$element, $index]); |
73 | 73 | } |
74 | 74 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return $this |
82 | 82 | */ |
83 | - public function __reverse(){ |
|
83 | + public function __reverse() { |
|
84 | 84 | $this->array = array_reverse($this->array); |
85 | 85 | $this->offset = 0; |
86 | 86 | |
@@ -90,21 +90,21 @@ discard block |
||
90 | 90 | /** |
91 | 91 | * @return mixed |
92 | 92 | */ |
93 | - public function __first(){ |
|
93 | + public function __first() { |
|
94 | 94 | return $this->array[0] ?? null; |
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
98 | 98 | * @return mixed |
99 | 99 | */ |
100 | - public function __last(){ |
|
100 | + public function __last() { |
|
101 | 101 | return $this->array[count($this->array) - 1] ?? null; |
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
105 | 105 | * @return $this |
106 | 106 | */ |
107 | - public function __clear(){ |
|
107 | + public function __clear() { |
|
108 | 108 | $this->array = []; |
109 | 109 | |
110 | 110 | return $this; |
@@ -129,15 +129,15 @@ discard block |
||
129 | 129 | */ |
130 | 130 | public function __findAll($callback):array{ |
131 | 131 | |
132 | - if(!is_callable($callback)){ |
|
132 | + if (!is_callable($callback)) { |
|
133 | 133 | throw new TraitException('invalid callback'); |
134 | 134 | } |
135 | 135 | |
136 | 136 | $return = []; |
137 | 137 | |
138 | - foreach($this->array as $index => $element){ |
|
138 | + foreach ($this->array as $index => $element) { |
|
139 | 139 | |
140 | - if(call_user_func_array($callback, [$element, $index]) === true){ |
|
140 | + if (call_user_func_array($callback, [$element, $index]) === true) { |
|
141 | 141 | $return[] = $element; |
142 | 142 | } |
143 | 143 | |
@@ -156,15 +156,15 @@ discard block |
||
156 | 156 | */ |
157 | 157 | public function __reject($callback):array{ |
158 | 158 | |
159 | - if(!is_callable($callback)){ |
|
159 | + if (!is_callable($callback)) { |
|
160 | 160 | throw new TraitException('invalid callback'); |
161 | 161 | } |
162 | 162 | |
163 | 163 | $return = []; |
164 | 164 | |
165 | - foreach($this->array as $index => $element){ |
|
165 | + foreach ($this->array as $index => $element) { |
|
166 | 166 | |
167 | - if(call_user_func_array($callback, [$element, $index]) !== true){ |
|
167 | + if (call_user_func_array($callback, [$element, $index]) !== true) { |
|
168 | 168 | $return[] = $element; |
169 | 169 | } |
170 | 170 |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @link http://php.net/manual/class.arrayaccess.php |
19 | 19 | */ |
20 | -trait ArrayAccessTrait{ |
|
20 | +trait ArrayAccessTrait { |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @var array |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * @link http://php.net/manual/arrayaccess.offsetget.php |
42 | 42 | * @inheritdoc |
43 | 43 | */ |
44 | - public function offsetGet($offset){ |
|
44 | + public function offsetGet($offset) { |
|
45 | 45 | return $this->array[$offset] ?? null; |
46 | 46 | } |
47 | 47 |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @link http://php.net/manual/class.traversable.php |
20 | 20 | */ |
21 | -trait IteratorTrait{ |
|
21 | +trait IteratorTrait { |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * @var array |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @link http://php.net/manual/iterator.current.php |
35 | 35 | * @inheritdoc |
36 | 36 | */ |
37 | - public function current(){ |
|
37 | + public function current() { |
|
38 | 38 | return $this->array[$this->offset] ?? null; |
39 | 39 | } |
40 | 40 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * @link http://php.net/manual/iterator.key.php |
51 | 51 | * @inheritdoc |
52 | 52 | */ |
53 | - public function key(){ |
|
53 | + public function key() { |
|
54 | 54 | return $this->offset; |
55 | 55 | } |
56 | 56 |
@@ -13,7 +13,7 @@ |
||
13 | 13 | /** |
14 | 14 | * a generic container with magic getter and setter |
15 | 15 | */ |
16 | -interface ImmutableSettingsInterface{ |
|
16 | +interface ImmutableSettingsInterface { |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * @param iterable|null $properties |
@@ -15,14 +15,14 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * A Container that turns methods into magic properties |
17 | 17 | */ |
18 | -trait Magic{ |
|
18 | +trait Magic { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @param string $name |
22 | 22 | * |
23 | 23 | * @return mixed|null |
24 | 24 | */ |
25 | - public function __get(string $name){ |
|
25 | + public function __get(string $name) { |
|
26 | 26 | return $this->get($name); |
27 | 27 | } |
28 | 28 | |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @return mixed|null |
43 | 43 | */ |
44 | - private function get(string $name){ |
|
44 | + private function get(string $name) { |
|
45 | 45 | $method = 'magic_get_'.$name; |
46 | 46 | |
47 | 47 | return method_exists($this, $method) ? $this->$method() : null; |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | private function set(string $name, $value):void{ |
57 | 57 | $method = 'magic_set_'.$name; |
58 | 58 | |
59 | - if(method_exists($this, $method)){ |
|
59 | + if (method_exists($this, $method)) { |
|
60 | 60 | $this->$method($value); |
61 | 61 | } |
62 | 62 |
@@ -12,6 +12,6 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\Traits; |
14 | 14 | |
15 | -abstract class ImmutableSettingsAbstract implements ImmutableSettingsInterface{ |
|
15 | +abstract class ImmutableSettingsAbstract implements ImmutableSettingsInterface { |
|
16 | 16 | use ImmutableSettingsContainer; |
17 | 17 | } |
@@ -45,9 +45,9 @@ |
||
45 | 45 | * |
46 | 46 | * @throws \chillerlan\Traits\Crypto\CryptoException |
47 | 47 | */ |
48 | - public function __construct(iterable $properties = null){ |
|
48 | + public function __construct(iterable $properties = null) { |
|
49 | 49 | |
50 | - if(!extension_loaded('sodium') || !function_exists('sodium_memzero')){ |
|
50 | + if (!extension_loaded('sodium') || !function_exists('sodium_memzero')) { |
|
51 | 51 | throw new CryptoException('sodium extension (PHP 7.2+) required!'); // @codeCoverageIgnore |
52 | 52 | } |
53 | 53 |
@@ -53,9 +53,9 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @throws \chillerlan\Traits\Crypto\CryptoException |
55 | 55 | */ |
56 | - public function __construct(iterable $properties = null){ |
|
56 | + public function __construct(iterable $properties = null) { |
|
57 | 57 | |
58 | - if(!extension_loaded('sodium') || !function_exists('sodium_memzero')){ |
|
58 | + if (!extension_loaded('sodium') || !function_exists('sodium_memzero')) { |
|
59 | 59 | throw new CryptoException('sodium extension (PHP 7.2+) required!'); // @codeCoverageIgnore |
60 | 60 | } |
61 | 61 | |
@@ -71,14 +71,14 @@ discard block |
||
71 | 71 | */ |
72 | 72 | protected function checkKeypair(int $secretLength = null, int $PublicLength = null):void{ |
73 | 73 | |
74 | - if($secretLength !== null){ |
|
75 | - if(!$this->keypair->secret || strlen($this->keypair->secret) !== $secretLength){ |
|
74 | + if ($secretLength !== null) { |
|
75 | + if (!$this->keypair->secret || strlen($this->keypair->secret) !== $secretLength) { |
|
76 | 76 | throw new CryptoException('invalid secret key'); |
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
80 | - if($PublicLength !== null){ |
|
81 | - if(!$this->keypair->public || strlen($this->keypair->public) !== $PublicLength){ |
|
80 | + if ($PublicLength !== null) { |
|
81 | + if (!$this->keypair->public || strlen($this->keypair->public) !== $PublicLength) { |
|
82 | 82 | throw new CryptoException('invalid public key'); |
83 | 83 | } |
84 | 84 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | protected function checkMessage(string $message):string{ |
95 | 95 | $message = trim($message); |
96 | 96 | |
97 | - if(empty($message)){ |
|
97 | + if (empty($message)) { |
|
98 | 98 | throw new CryptoException('invalid message'); |
99 | 99 | } |
100 | 100 |
@@ -17,24 +17,24 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * a generic container with magic getter and setter |
19 | 19 | */ |
20 | -trait ImmutableSettingsContainer{ |
|
20 | +trait ImmutableSettingsContainer { |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @param iterable|null $properties |
24 | 24 | */ |
25 | - public function __construct(iterable $properties = null){ |
|
25 | + public function __construct(iterable $properties = null) { |
|
26 | 26 | |
27 | - if(!empty($properties)){ |
|
27 | + if (!empty($properties)) { |
|
28 | 28 | $this->__fromIterable($properties); |
29 | 29 | } |
30 | 30 | |
31 | 31 | // call a method with trait name as replacement constructor for each trait |
32 | 32 | $traits = (new ReflectionClass($this))->getTraits(); |
33 | 33 | |
34 | - foreach($traits as $trait){ |
|
34 | + foreach ($traits as $trait) { |
|
35 | 35 | $method = $trait->getShortName(); |
36 | 36 | |
37 | - if(method_exists($this, $method)){ |
|
37 | + if (method_exists($this, $method)) { |
|
38 | 38 | call_user_func([$this, $trait->getShortName()]); |
39 | 39 | } |
40 | 40 | } |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | * |
46 | 46 | * @return mixed |
47 | 47 | */ |
48 | - public function __get(string $property){ |
|
48 | + public function __get(string $property) { |
|
49 | 49 | |
50 | - if($this->__isset($property)){ |
|
50 | + if ($this->__isset($property)) { |
|
51 | 51 | return $this->{$property}; |
52 | 52 | } |
53 | 53 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | public function __set(string $property, $value):void{ |
64 | 64 | |
65 | 65 | // avoid overwriting private properties |
66 | - if(property_exists($this, $property) && !$this->__isPrivate($property)){ |
|
66 | + if (property_exists($this, $property) && !$this->__isPrivate($property)) { |
|
67 | 67 | $this->{$property} = $value; |
68 | 68 | return; |
69 | 69 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | public function __unset(string $property):void{ |
98 | 98 | |
99 | 99 | // avoid unsetting private properties |
100 | - if($this->__isset($property)){ |
|
100 | + if ($this->__isset($property)) { |
|
101 | 101 | unset($this->{$property}); |
102 | 102 | } |
103 | 103 | |
@@ -116,10 +116,10 @@ discard block |
||
116 | 116 | public function __toArray():array{ |
117 | 117 | $data = []; |
118 | 118 | |
119 | - foreach($this as $property => $value){ |
|
119 | + foreach ($this as $property => $value) { |
|
120 | 120 | |
121 | 121 | // exclude private properties |
122 | - if($this->__isset($property)){ |
|
122 | + if ($this->__isset($property)) { |
|
123 | 123 | $data[$property] = $value; |
124 | 124 | } |
125 | 125 | |
@@ -133,9 +133,9 @@ discard block |
||
133 | 133 | * |
134 | 134 | * @return $this |
135 | 135 | */ |
136 | - public function __fromIterable(iterable $properties){ |
|
136 | + public function __fromIterable(iterable $properties) { |
|
137 | 137 | |
138 | - foreach($properties as $key => $value){ |
|
138 | + foreach ($properties as $key => $value) { |
|
139 | 139 | $this->__set($key, $value); |
140 | 140 | } |
141 | 141 | |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * |
157 | 157 | * @return $this |
158 | 158 | */ |
159 | - public function __fromJSON(string $json){ |
|
159 | + public function __fromJSON(string $json) { |
|
160 | 160 | return $this->__fromIterable(json_decode($json, true)); |
161 | 161 | } |
162 | 162 |