diff --git a/src/Iterator/CsvFileIterator.php b/src/Iterator/CsvFileIterator.php index 0101935..76b4edd 100644 --- a/src/Iterator/CsvFileIterator.php +++ b/src/Iterator/CsvFileIterator.php @@ -76,14 +76,10 @@ class CsvFileIterator implements \Iterator */ public function __construct($file, bool $headerRow = false, string $delimiter = ',', string $enclosure = '"', string $escape = '\\') { - if (is_resource($file)) { - $this->handle = $file; - } else { - $this->handle = @ fopen($file, 'rb'); + $this->handle = (is_resource($file) ? $file : @ fopen($file, 'rb')); - if ($this->handle === false) { - throw new \InvalidArgumentException('Cannot open file for reading: ' . $file); - } + if ($this->handle === false) { + throw new \InvalidArgumentException('Cannot open file for reading: ' . $file); } $this->headerRow = $headerRow; diff --git a/src/Iterator/CsvJsonFileIterator.php b/src/Iterator/CsvJsonFileIterator.php index 1cb2317..66d9785 100644 --- a/src/Iterator/CsvJsonFileIterator.php +++ b/src/Iterator/CsvJsonFileIterator.php @@ -42,14 +42,10 @@ class CsvJsonFileIterator implements \Iterator */ public function __construct($file) { - if (is_resource($file)) { - $this->handle = $file; - } else { - $this->handle = @ fopen($file, 'rb'); - - if ($this->handle === false) { - throw new \InvalidArgumentException('Cannot open file for reading: ' . $file); - } + $this->handle = (is_resource($file) ? $file : @ fopen($file, 'rb')); + + if ($this->handle === false) { + throw new \InvalidArgumentException('Cannot open file for reading: ' . $file); } $this->current = $this->readRow(); diff --git a/src/ObjectArrayStorage.php b/src/ObjectArrayStorage.php index 8df0c37..aeb3967 100644 --- a/src/ObjectArrayStorage.php +++ b/src/ObjectArrayStorage.php @@ -49,7 +49,7 @@ public function get($object) : array { $values = $this->storage->get($object); - return ($values === null) ? [] : $values; + return isset($values) ? $values : []; } /** diff --git a/src/ObjectStorage.php b/src/ObjectStorage.php index df950d3..8664f47 100644 --- a/src/ObjectStorage.php +++ b/src/ObjectStorage.php @@ -55,11 +55,7 @@ public function get($object) { $hash = spl_object_hash($object); - if (isset($this->data[$hash])) { - return $this->data[$hash]; - } - - return null; + return isset($this->data[$hash]) ? $this->data[$hash] : null; } /** @@ -142,11 +138,11 @@ public function offsetGet($object) { $hash = spl_object_hash($object); - if (isset($this->objects[$hash])) { - return $this->data[$hash]; + if (! isset($this->objects[$hash])) { + throw new \UnexpectedValueException('Object not found.'); } - throw new \UnexpectedValueException('Object not found.'); + return $this->data[$hash]; } /**