@@ -3,73 +3,73 @@ |
||
| 3 | 3 | namespace FigTree\Config\Concerns; |
| 4 | 4 | |
| 5 | 5 | use FigTree\Config\Exceptions\{ |
| 6 | - ReadOnlyException, |
|
| 6 | + ReadOnlyException, |
|
| 7 | 7 | }; |
| 8 | 8 | |
| 9 | 9 | trait ArrayAccessData |
| 10 | 10 | { |
| 11 | - protected array $data = []; |
|
| 11 | + protected array $data = []; |
|
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Magic method to handle key_exists/isset checks of an array value on the object. |
|
| 15 | - * |
|
| 16 | - * @param string|int $offset |
|
| 17 | - * |
|
| 18 | - * @return boolean |
|
| 19 | - */ |
|
| 20 | - public function offsetExists($offset): bool |
|
| 21 | - { |
|
| 22 | - return key_exists($offset, $this->data); |
|
| 23 | - } |
|
| 13 | + /** |
|
| 14 | + * Magic method to handle key_exists/isset checks of an array value on the object. |
|
| 15 | + * |
|
| 16 | + * @param string|int $offset |
|
| 17 | + * |
|
| 18 | + * @return boolean |
|
| 19 | + */ |
|
| 20 | + public function offsetExists($offset): bool |
|
| 21 | + { |
|
| 22 | + return key_exists($offset, $this->data); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Magic method to handle retrieval of an array value on the object. |
|
| 27 | - * |
|
| 28 | - * @param string|int $offset |
|
| 29 | - * |
|
| 30 | - * @return mixed |
|
| 31 | - */ |
|
| 32 | - public function offsetGet($offset) |
|
| 33 | - { |
|
| 34 | - return $this->data[$offset] ?? null; |
|
| 35 | - } |
|
| 25 | + /** |
|
| 26 | + * Magic method to handle retrieval of an array value on the object. |
|
| 27 | + * |
|
| 28 | + * @param string|int $offset |
|
| 29 | + * |
|
| 30 | + * @return mixed |
|
| 31 | + */ |
|
| 32 | + public function offsetGet($offset) |
|
| 33 | + { |
|
| 34 | + return $this->data[$offset] ?? null; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Magic method to handle modification of an array value on the object. |
|
| 39 | - * |
|
| 40 | - * @param string|int $offset |
|
| 41 | - * @param mixed $value |
|
| 42 | - * |
|
| 43 | - * @return void |
|
| 44 | - * |
|
| 45 | - * @throws \FigTree\Config\Exceptions\ReadOnlyException |
|
| 46 | - */ |
|
| 47 | - public function offsetSet($offset, $value): void |
|
| 48 | - { |
|
| 49 | - throw new ReadOnlyException($offset); |
|
| 50 | - } |
|
| 37 | + /** |
|
| 38 | + * Magic method to handle modification of an array value on the object. |
|
| 39 | + * |
|
| 40 | + * @param string|int $offset |
|
| 41 | + * @param mixed $value |
|
| 42 | + * |
|
| 43 | + * @return void |
|
| 44 | + * |
|
| 45 | + * @throws \FigTree\Config\Exceptions\ReadOnlyException |
|
| 46 | + */ |
|
| 47 | + public function offsetSet($offset, $value): void |
|
| 48 | + { |
|
| 49 | + throw new ReadOnlyException($offset); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Magic method to handle removal of an array value on the object. |
|
| 54 | - * |
|
| 55 | - * @param string|int $offset |
|
| 56 | - * |
|
| 57 | - * @return void |
|
| 58 | - * |
|
| 59 | - * @throws \FigTree\Config\Exceptions\ReadOnlyException |
|
| 60 | - */ |
|
| 61 | - public function offsetUnset($offset): void |
|
| 62 | - { |
|
| 63 | - throw new ReadOnlyException($offset); |
|
| 64 | - } |
|
| 52 | + /** |
|
| 53 | + * Magic method to handle removal of an array value on the object. |
|
| 54 | + * |
|
| 55 | + * @param string|int $offset |
|
| 56 | + * |
|
| 57 | + * @return void |
|
| 58 | + * |
|
| 59 | + * @throws \FigTree\Config\Exceptions\ReadOnlyException |
|
| 60 | + */ |
|
| 61 | + public function offsetUnset($offset): void |
|
| 62 | + { |
|
| 63 | + throw new ReadOnlyException($offset); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Convert the object into an array. |
|
| 68 | - * |
|
| 69 | - * @return array |
|
| 70 | - */ |
|
| 71 | - public function toArray(): array |
|
| 72 | - { |
|
| 73 | - return $this->data; |
|
| 74 | - } |
|
| 66 | + /** |
|
| 67 | + * Convert the object into an array. |
|
| 68 | + * |
|
| 69 | + * @return array |
|
| 70 | + */ |
|
| 71 | + public function toArray(): array |
|
| 72 | + { |
|
| 73 | + return $this->data; |
|
| 74 | + } |
|
| 75 | 75 | } |
@@ -4,129 +4,129 @@ |
||
| 4 | 4 | |
| 5 | 5 | use FigTree\Exceptions\UnreadablePathException; |
| 6 | 6 | use FigTree\Config\Exceptions\{ |
| 7 | - InvalidConfigFileException, |
|
| 7 | + InvalidConfigFileException, |
|
| 8 | 8 | }; |
| 9 | 9 | use FigTree\Exceptions\{ |
| 10 | - InvalidFileException, |
|
| 11 | - InvalidPathException, |
|
| 10 | + InvalidFileException, |
|
| 11 | + InvalidPathException, |
|
| 12 | 12 | }; |
| 13 | 13 | use FigTree\Config\Concerns\ArrayAccessData; |
| 14 | 14 | use FigTree\Config\Contracts\ConfigInterface; |
| 15 | 15 | |
| 16 | 16 | abstract class AbstractConfig implements ConfigInterface |
| 17 | 17 | { |
| 18 | - use ArrayAccessData; |
|
| 19 | - |
|
| 20 | - protected string $fileName; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Get the name of the underlying Config file. |
|
| 24 | - * |
|
| 25 | - * @return string |
|
| 26 | - */ |
|
| 27 | - public function getFileName(): string |
|
| 28 | - { |
|
| 29 | - return $this->fileName; |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Convert the object into JSON. |
|
| 34 | - * |
|
| 35 | - * @param integer $options |
|
| 36 | - * @param integer $depth |
|
| 37 | - * |
|
| 38 | - * @return string |
|
| 39 | - */ |
|
| 40 | - public function toJson(int $options = 0, int $depth = 512): string |
|
| 41 | - { |
|
| 42 | - if (($options & JSON_THROW_ON_ERROR) === 0) { |
|
| 43 | - $options |= JSON_THROW_ON_ERROR; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - return json_encode($this, $options, $depth); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Convert the object into a string. |
|
| 51 | - * |
|
| 52 | - * @return string |
|
| 53 | - */ |
|
| 54 | - public function toString(): string |
|
| 55 | - { |
|
| 56 | - return $this->__toString(); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Magic method called on JSON serialization of the object. |
|
| 61 | - * |
|
| 62 | - * @return array The data to be serialized. |
|
| 63 | - */ |
|
| 64 | - public function jsonSerialize() |
|
| 65 | - { |
|
| 66 | - return $this->toArray(); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Magic method called during serialization to a string. |
|
| 71 | - * |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 74 | - public function __toString() |
|
| 75 | - { |
|
| 76 | - return serialize($this); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Set the resolved filename of the Config file and read in its data. |
|
| 81 | - * |
|
| 82 | - * @param string $fileName |
|
| 83 | - * |
|
| 84 | - * @return $this |
|
| 85 | - * |
|
| 86 | - * @throws \FigTree\Exceptions\InvalidPathException |
|
| 87 | - * @throws \FigTree\Exceptions\InvalidFileException |
|
| 88 | - */ |
|
| 89 | - protected function setFileName(string $fileName) |
|
| 90 | - { |
|
| 91 | - $path = realpath($fileName); |
|
| 92 | - |
|
| 93 | - if (empty($path)) { |
|
| 94 | - throw new InvalidPathException($fileName); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - if (!is_file($path)) { |
|
| 98 | - throw new InvalidFileException($path); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - $this->fileName = $path; |
|
| 102 | - |
|
| 103 | - return $this->readData(); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Read the result of the Config file into the object's data. |
|
| 108 | - * |
|
| 109 | - * @return $this |
|
| 110 | - * |
|
| 111 | - * @throws \FigTree\Exceptions\UnreadablePathException |
|
| 112 | - * @throws \FigTree\Config\Exceptions\InvalidConfigFileException |
|
| 113 | - */ |
|
| 114 | - protected function readData(): ConfigInterface |
|
| 115 | - { |
|
| 116 | - if (!is_readable($this->fileName)) { |
|
| 117 | - throw new UnreadablePathException($this->fileName); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - $reader = $this->createReader(); |
|
| 121 | - |
|
| 122 | - $data = $reader->read($this->fileName); |
|
| 123 | - |
|
| 124 | - if (!is_array($data)) { |
|
| 125 | - throw new InvalidConfigFileException($this->fileName); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - $this->data = $data; |
|
| 129 | - |
|
| 130 | - return $this; |
|
| 131 | - } |
|
| 18 | + use ArrayAccessData; |
|
| 19 | + |
|
| 20 | + protected string $fileName; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Get the name of the underlying Config file. |
|
| 24 | + * |
|
| 25 | + * @return string |
|
| 26 | + */ |
|
| 27 | + public function getFileName(): string |
|
| 28 | + { |
|
| 29 | + return $this->fileName; |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Convert the object into JSON. |
|
| 34 | + * |
|
| 35 | + * @param integer $options |
|
| 36 | + * @param integer $depth |
|
| 37 | + * |
|
| 38 | + * @return string |
|
| 39 | + */ |
|
| 40 | + public function toJson(int $options = 0, int $depth = 512): string |
|
| 41 | + { |
|
| 42 | + if (($options & JSON_THROW_ON_ERROR) === 0) { |
|
| 43 | + $options |= JSON_THROW_ON_ERROR; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + return json_encode($this, $options, $depth); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Convert the object into a string. |
|
| 51 | + * |
|
| 52 | + * @return string |
|
| 53 | + */ |
|
| 54 | + public function toString(): string |
|
| 55 | + { |
|
| 56 | + return $this->__toString(); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Magic method called on JSON serialization of the object. |
|
| 61 | + * |
|
| 62 | + * @return array The data to be serialized. |
|
| 63 | + */ |
|
| 64 | + public function jsonSerialize() |
|
| 65 | + { |
|
| 66 | + return $this->toArray(); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Magic method called during serialization to a string. |
|
| 71 | + * |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | + public function __toString() |
|
| 75 | + { |
|
| 76 | + return serialize($this); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Set the resolved filename of the Config file and read in its data. |
|
| 81 | + * |
|
| 82 | + * @param string $fileName |
|
| 83 | + * |
|
| 84 | + * @return $this |
|
| 85 | + * |
|
| 86 | + * @throws \FigTree\Exceptions\InvalidPathException |
|
| 87 | + * @throws \FigTree\Exceptions\InvalidFileException |
|
| 88 | + */ |
|
| 89 | + protected function setFileName(string $fileName) |
|
| 90 | + { |
|
| 91 | + $path = realpath($fileName); |
|
| 92 | + |
|
| 93 | + if (empty($path)) { |
|
| 94 | + throw new InvalidPathException($fileName); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + if (!is_file($path)) { |
|
| 98 | + throw new InvalidFileException($path); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + $this->fileName = $path; |
|
| 102 | + |
|
| 103 | + return $this->readData(); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Read the result of the Config file into the object's data. |
|
| 108 | + * |
|
| 109 | + * @return $this |
|
| 110 | + * |
|
| 111 | + * @throws \FigTree\Exceptions\UnreadablePathException |
|
| 112 | + * @throws \FigTree\Config\Exceptions\InvalidConfigFileException |
|
| 113 | + */ |
|
| 114 | + protected function readData(): ConfigInterface |
|
| 115 | + { |
|
| 116 | + if (!is_readable($this->fileName)) { |
|
| 117 | + throw new UnreadablePathException($this->fileName); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + $reader = $this->createReader(); |
|
| 121 | + |
|
| 122 | + $data = $reader->read($this->fileName); |
|
| 123 | + |
|
| 124 | + if (!is_array($data)) { |
|
| 125 | + throw new InvalidConfigFileException($this->fileName); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + $this->data = $data; |
|
| 129 | + |
|
| 130 | + return $this; |
|
| 131 | + } |
|
| 132 | 132 | } |
@@ -6,13 +6,13 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ConfigReader implements ConfigReaderInterface |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Read the contents of the Config file. |
|
| 11 | - * |
|
| 12 | - * @return array |
|
| 13 | - */ |
|
| 14 | - public function read(string $filename): array |
|
| 15 | - { |
|
| 16 | - return (require $filename); |
|
| 17 | - } |
|
| 9 | + /** |
|
| 10 | + * Read the contents of the Config file. |
|
| 11 | + * |
|
| 12 | + * @return array |
|
| 13 | + */ |
|
| 14 | + public function read(string $filename): array |
|
| 15 | + { |
|
| 16 | + return (require $filename); |
|
| 17 | + } |
|
| 18 | 18 | } |
@@ -6,5 +6,5 @@ |
||
| 6 | 6 | |
| 7 | 7 | abstract class AbstractTestCase extends TestCase |
| 8 | 8 | { |
| 9 | - // |
|
| 9 | + // |
|
| 10 | 10 | } |
@@ -8,17 +8,17 @@ |
||
| 8 | 8 | |
| 9 | 9 | class TestPrinter extends DefaultResultPrinter |
| 10 | 10 | { |
| 11 | - protected function printDefect(TestFailure $defect, int $count): void |
|
| 12 | - { |
|
| 13 | - $this->printDefectHeader($defect, $count); |
|
| 11 | + protected function printDefect(TestFailure $defect, int $count): void |
|
| 12 | + { |
|
| 13 | + $this->printDefectHeader($defect, $count); |
|
| 14 | 14 | |
| 15 | - $exception = $defect->thrownException(); |
|
| 15 | + $exception = $defect->thrownException(); |
|
| 16 | 16 | |
| 17 | - if (!($exception instanceof Exception)) { |
|
| 18 | - $this->write(sprintf('%s:%u', $exception->getFile(), $exception->getLine())); |
|
| 19 | - $this->write(PHP_EOL); |
|
| 20 | - } |
|
| 17 | + if (!($exception instanceof Exception)) { |
|
| 18 | + $this->write(sprintf('%s:%u', $exception->getFile(), $exception->getLine())); |
|
| 19 | + $this->write(PHP_EOL); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - $this->printDefectTrace($defect); |
|
| 23 | - } |
|
| 22 | + $this->printDefectTrace($defect); |
|
| 23 | + } |
|
| 24 | 24 | } |