From 017fa91f7293661720bd25d56b52a731ab6e3c15 Mon Sep 17 00:00:00 2001 From: Ori Hoch Date: Mon, 31 Jul 2017 13:50:23 +0300 Subject: [PATCH] style fix --- src/Datapackages/BaseDatapackage.php | 12 ++++++------ src/Resources/BaseResource.php | 7 ++++--- src/Resources/TabularResource.php | 2 +- src/Utils.php | 4 ++-- src/Validators/ResourceValidator.php | 1 + tests/DatapackageTest.php | 14 ++++++++------ 6 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/Datapackages/BaseDatapackage.php b/src/Datapackages/BaseDatapackage.php index 14b06a5..2f33f24 100644 --- a/src/Datapackages/BaseDatapackage.php +++ b/src/Datapackages/BaseDatapackage.php @@ -162,18 +162,18 @@ public function save($zip_filename) $zippy = Zippy::load(); $base = tempnam(sys_get_temp_dir(), 'datapackage-zip-'); $files = [ - "datapackage.json" => $base."datapackage.json" + 'datapackage.json' => $base.'datapackage.json', ]; $ri = 0; foreach ($this as $resource) { - $fileNames = $resource->save($base."resource-".$ri); + $fileNames = $resource->save($base.'resource-'.$ri); foreach ($fileNames as $fileName) { - $relname = str_replace($base."resource-".$ri, "", $fileName); - $files["resource-".$ri.$relname] = $fileName; + $relname = str_replace($base.'resource-'.$ri, '', $fileName); + $files['resource-'.$ri.$relname] = $fileName; } - $ri++; + ++$ri; } - $this->saveDescriptor($files["datapackage.json"]); + $this->saveDescriptor($files['datapackage.json']); $zippy->create($zip_filename, $files); foreach (array_values($files) as $file) { unlink($file); diff --git a/src/Resources/BaseResource.php b/src/Resources/BaseResource.php index 3f0c860..913a5be 100644 --- a/src/Resources/BaseResource.php +++ b/src/Resources/BaseResource.php @@ -143,7 +143,7 @@ public function valid() public function getFileExtension() { - return ""; + return ''; } public function save($baseFilename) @@ -156,12 +156,13 @@ public function save($baseFilename) if ($numDataStreams == 1) { $filename = $baseFilename.$this->getFileExtension(); } else { - $filename = $baseFilename."-data-".$i.$this->getFileExtension(); + $filename = $baseFilename.'-data-'.$i.$this->getFileExtension(); } $fileNames[] = $filename; $dataStream->save($filename); - $i++; + ++$i; } + return $fileNames; } diff --git a/src/Resources/TabularResource.php b/src/Resources/TabularResource.php index 533f21b..2ae847a 100644 --- a/src/Resources/TabularResource.php +++ b/src/Resources/TabularResource.php @@ -15,7 +15,7 @@ public function schema() public function getFileExtension() { - return ".csv"; + return '.csv'; } /** diff --git a/src/Utils.php b/src/Utils.php index 4d006ca..ed85009 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -31,9 +31,9 @@ public static function objectify($val) public static function removeDir($path) { - $files = glob($path . '/*'); + $files = glob($path.'/*'); foreach ($files as $file) { - is_dir($file) ? Utils::removeDir($file) : unlink($file); + is_dir($file) ? self::removeDir($file) : unlink($file); } rmdir($path); } diff --git a/src/Validators/ResourceValidator.php b/src/Validators/ResourceValidator.php index 702a69a..4b0d23b 100644 --- a/src/Validators/ResourceValidator.php +++ b/src/Validators/ResourceValidator.php @@ -24,6 +24,7 @@ protected function getValidationProfile() protected function getDescriptorForValidation() { $descriptor = clone $this->descriptor; + return $descriptor; } diff --git a/tests/DatapackageTest.php b/tests/DatapackageTest.php index b125b5f..b799a3a 100644 --- a/tests/DatapackageTest.php +++ b/tests/DatapackageTest.php @@ -455,20 +455,22 @@ public function testCreateEditDatapackageDescriptor() ['id' => 3, 'name' => 'three'], ], $package->resource('my-renamed-tabular-resource')->read()); - $filename = tempnam(sys_get_temp_dir(), 'datapackage-php-tests-').".zip"; + $filename = tempnam(sys_get_temp_dir(), 'datapackage-php-tests-').'.zip'; $package->save($filename); $zippy = Zippy::load(); $tempdir = sys_get_temp_dir().DIRECTORY_SEPARATOR.'datapackage-php-tests-zipdir'; - if (file_exists($tempdir)) Utils::removeDir($tempdir); + if (file_exists($tempdir)) { + Utils::removeDir($tempdir); + } mkdir($tempdir); $archive = $zippy->open($filename); $archive->extract($tempdir); unlink($filename); $tempdir = $tempdir.DIRECTORY_SEPARATOR; - $this->assertEquals($expectedDatapackageDescriptor, json_decode(file_get_contents($tempdir."datapackage.json"))); - $this->assertEquals("foo", file_get_contents($tempdir."resource-0-data-0")); - $this->assertEquals("testing 改善\n", file_get_contents($tempdir."resource-0-data-1")); - $this->assertEquals("id,name\n1,one\n2,two\n3,three\n", file_get_contents($tempdir."resource-1.csv")); + $this->assertEquals($expectedDatapackageDescriptor, json_decode(file_get_contents($tempdir.'datapackage.json'))); + $this->assertEquals('foo', file_get_contents($tempdir.'resource-0-data-0')); + $this->assertEquals("testing 改善\n", file_get_contents($tempdir.'resource-0-data-1')); + $this->assertEquals("id,name\n1,one\n2,two\n3,three\n", file_get_contents($tempdir.'resource-1.csv')); } public function testStringPath()