From f6a3dd908727ad8f27110a0d54f87d9242419c99 Mon Sep 17 00:00:00 2001 From: David Santucci Date: Mon, 14 Aug 2017 12:13:54 -0400 Subject: [PATCH 1/2] Insure "path" is an array. --- src/Validators/DatapackageValidator.php | 12 ++++++++---- src/Validators/ResourceValidator.php | 4 +++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Validators/DatapackageValidator.php b/src/Validators/DatapackageValidator.php index 6a7a0e7..b9beec8 100644 --- a/src/Validators/DatapackageValidator.php +++ b/src/Validators/DatapackageValidator.php @@ -29,11 +29,15 @@ protected function getDescriptorForValidation() foreach ($descriptor->resources as &$resource) { if (is_object($resource)) { $resource = clone $resource; - if (isset($resource->path) && is_array($resource->path)) { - foreach ($resource->path as &$url) { - if (is_string($url)) { - $url = 'file://'.$url; + if (isset($resource->path)) { + if (is_array($resource->path)) { + foreach ($resource->path as &$url) { + if (is_string($url)) { + $url = 'file://'.$url; + } } + } else if (is_string($resource->path)) { + $resource->path .= 'file://' . $resource->path; } } } diff --git a/src/Validators/ResourceValidator.php b/src/Validators/ResourceValidator.php index 4b0d23b..9bec5bf 100644 --- a/src/Validators/ResourceValidator.php +++ b/src/Validators/ResourceValidator.php @@ -44,7 +44,9 @@ protected function getResourceClass() protected function validateKeys() { $resourceClass = $this->getResourceClass(); - foreach ($this->descriptor->path as $dataSource) { + // DS: path can be a string or an array + $sources = is_array($this->descriptor->path) ? $this->descriptor->path : array($this->descriptor->path); + foreach ($sources as $dataSource) { foreach ($resourceClass::validateDataSource($dataSource, $this->basePath) as $error) { $this->errors[] = $error; } From 62ce08fa67e47e7be19683f1e9fea087428300bb Mon Sep 17 00:00:00 2001 From: Ori Hoch Date: Wed, 30 Aug 2017 08:35:28 +0300 Subject: [PATCH 2/2] automatic style fix - using `composer style-fix` --- src/Validators/DatapackageValidator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Validators/DatapackageValidator.php b/src/Validators/DatapackageValidator.php index b9beec8..2862b18 100644 --- a/src/Validators/DatapackageValidator.php +++ b/src/Validators/DatapackageValidator.php @@ -36,8 +36,8 @@ protected function getDescriptorForValidation() $url = 'file://'.$url; } } - } else if (is_string($resource->path)) { - $resource->path .= 'file://' . $resource->path; + } elseif (is_string($resource->path)) { + $resource->path .= 'file://'.$resource->path; } } }