Skip to content

Commit

Permalink
style fix
Browse files Browse the repository at this point in the history
  • Loading branch information
OriHoch committed Jul 31, 2017
1 parent 62fb384 commit 017fa91
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
12 changes: 6 additions & 6 deletions src/Datapackages/BaseDatapackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions src/Resources/BaseResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function valid()

public function getFileExtension()
{
return "";
return '';
}

public function save($baseFilename)
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Resources/TabularResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function schema()

public function getFileExtension()
{
return ".csv";
return '.csv';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/Validators/ResourceValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ protected function getValidationProfile()
protected function getDescriptorForValidation()
{
$descriptor = clone $this->descriptor;

return $descriptor;
}

Expand Down
14 changes: 8 additions & 6 deletions tests/DatapackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 017fa91

Please sign in to comment.