Skip to content

Commit 297a370

Browse files
committed
style fix
1 parent f7f98c9 commit 297a370

7 files changed

Lines changed: 76 additions & 73 deletions

File tree

src/DataStreams/TabularInlineDataStream.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ protected function getDataSourceObject()
1313
if (is_array($data)) {
1414
$numFields = count($this->schema->fields());
1515
$objRows = [];
16-
if (array_sum(array_keys($data[0])) == array_sum(range(0, $numFields-1))) {
16+
if (array_sum(array_keys($data[0])) == array_sum(range(0, $numFields - 1))) {
1717
// Row Arrays - convert to Row Objects
1818
$header = array_shift($data);
1919
foreach ($data as $row) {
@@ -27,6 +27,7 @@ protected function getDataSourceObject()
2727
// Row Objects - no processing needed
2828
$objRows = $data;
2929
}
30+
3031
return new NativeDataSource($objRows);
3132
} else {
3233
throw new DataStreamOpenException('inline tabular data must be an array');

src/Package.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
class Package
66
{
7-
87
public static function load($source, $basePath = null)
98
{
109
return Factory::datapackage($source, $basePath);
@@ -18,9 +17,11 @@ public static function validate($source, $basePath = null)
1817
public static function create($descriptor = null, $basePath = null)
1918
{
2019
$descriptor = Utils::objectify($descriptor);
21-
if ($descriptor && !isset($descriptor->resources)) $descriptor->resources = [];
20+
if ($descriptor && !isset($descriptor->resources)) {
21+
$descriptor->resources = [];
22+
}
2223
$packageClass = Factory::getDatapackageClass($descriptor);
24+
2325
return new $packageClass($descriptor, $basePath, true);
2426
}
25-
2627
}

src/Resource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44

55
class Resource
66
{
7-
87
public static function load($descriptor, $basePath = null)
98
{
109
$descriptor = Utils::objectify($descriptor);
10+
1111
return Factory::resource($descriptor, $basePath);
1212
}
1313

1414
public static function create($descriptor, $basePath = null)
1515
{
1616
$descriptor = Utils::objectify($descriptor);
1717
$skipValidations = true;
18+
1819
return Factory::resource($descriptor, $basePath, $skipValidations);
1920
}
20-
2121
}

src/Resources/BaseResource.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ public static function handlesDescriptor($descriptor)
3737
return static::handlesProfile(Registry::getResourceValidationProfile($descriptor));
3838
}
3939

40-
public function read($options=null)
40+
public function read($options = null)
4141
{
4242
$rows = [];
4343
foreach ($this as $row) {
4444
$rows[] = $row;
4545
}
46+
4647
return $rows;
4748
}
4849

@@ -52,12 +53,13 @@ public function dataStreams()
5253
$this->dataStreams = [];
5354
foreach ($this->path() as $path) {
5455
$this->dataStreams[] = $this->getDataStream($path);
55-
};
56+
}
5657
$data = $this->data();
5758
if ($data) {
5859
$this->dataStreams[] = $this->getInlineDataStream($data);
5960
}
6061
}
62+
6163
return $this->dataStreams;
6264
}
6365

@@ -84,6 +86,7 @@ public function path()
8486
if (!is_array($path)) {
8587
$path = [$path];
8688
}
89+
8790
return $path;
8891
} else {
8992
return [];
@@ -127,7 +130,7 @@ public function valid()
127130
// current data stream is still valid
128131
return true;
129132
} else {
130-
$this->currentDataStream++;
133+
++$this->currentDataStream;
131134
if (isset($dataStreams[$this->currentDataStream])) {
132135
// current data stream is done, but we have another data stream
133136
return true;

src/Validators/DatapackageValidationError.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function getMessage()
1919
case static::DATA_STREAM_FAILURE:
2020
return "resource {$this->extraDetails['resource']}"
2121
//."data stream {$this->extraDetails['dataStream']}"
22-
.($this->extraDetails['line']?", line number {$this->extraDetails['line']}":"")
22+
.($this->extraDetails['line'] ? ", line number {$this->extraDetails['line']}" : '')
2323
.': '.$this->extraDetails['error'];
2424
default:
2525
return parent::getMessage();

tests/DatapackageTest.php

Lines changed: 59 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
use frictionlessdata\tableschema\InferSchema;
1212
use frictionlessdata\tableschema\Table;
1313
use frictionlessdata\tableschema\DataSources\CsvDataSource;
14-
use frictionlessdata\datapackage\Resources\DefaultResource;
15-
use frictionlessdata\datapackage\Resources\TabularResource;
1614

1715
class DatapackageTest extends TestCase
1816
{
@@ -271,7 +269,7 @@ public function testDatapackageResources()
271269

272270
// add a resource
273271
$this->assertCount(1, $datapackage->resources());
274-
$datapackage->resource("new-resource", [
272+
$datapackage->resource('new-resource', [
275273
'path' => ['tests/fixtures/foo.txt', 'tests/fixtures/baz.txt'],
276274
]);
277275
$this->assertCount(2, $datapackage->resources());
@@ -329,11 +327,11 @@ public function testCreateEditDatapackageDescriptor()
329327
// create static method allows to create a new datapackage or resource without validation
330328
// with shortcut arguments for common use-cases
331329
$package = Package::create([
332-
"name" => 'my-datapackage-name',
333-
"resources" => [
334-
["name" => "my-default-resource"],
335-
["name" => "my-tabular-resource", "profile" => "tabular-data-resource"]
336-
]
330+
'name' => 'my-datapackage-name',
331+
'resources' => [
332+
['name' => 'my-default-resource'],
333+
['name' => 'my-tabular-resource', 'profile' => 'tabular-data-resource'],
334+
],
337335
]);
338336
// the tabular resource is missing schema, but it doesn't fail
339337
// when creating a datapackage or resource with the create method it doesn't validate
@@ -345,17 +343,17 @@ public function testCreateEditDatapackageDescriptor()
345343
],
346344
(object) [
347345
'name' => 'my-tabular-resource',
348-
"profile" => "tabular-data-resource"
346+
'profile' => 'tabular-data-resource',
349347
],
350348
],
351349
], $package->descriptor());
352350
// you can now modify the descriptor further by editing the descriptor directly
353-
$package->descriptor()->resources[1]->name = "my-renamed-tabular-resource";
351+
$package->descriptor()->resources[1]->name = 'my-renamed-tabular-resource';
354352
$package->descriptor()->resources[1]->schema = [
355-
"fields" => [
356-
["name" => "id", "type" => "integer"],
357-
["name" => "name", "type" => "string"]
358-
]
353+
'fields' => [
354+
['name' => 'id', 'type' => 'integer'],
355+
['name' => 'name', 'type' => 'string'],
356+
],
359357
];
360358
// when you are done you can revalidate
361359
try {
@@ -380,7 +378,7 @@ public function testCreateEditDatapackageDescriptor()
380378

381379
$defaultSecondPath = tempnam(sys_get_temp_dir(), 'datapackage-php-tests-').'.csv';
382380
$package->resource('my-default-resource')->descriptor()->path[] = $defaultSecondPath;
383-
file_put_contents($defaultSecondPath, "BAHHH");
381+
file_put_contents($defaultSecondPath, 'BAHHH');
384382

385383
$tabularDataFilename = tempnam(sys_get_temp_dir(), 'datapackage-php-tests-').'.csv';
386384
$package->resource('my-renamed-tabular-resource')->descriptor()->path[] = $tabularDataFilename;
@@ -401,7 +399,7 @@ public function testCreateEditDatapackageDescriptor()
401399
$this->assertContains('Failed to open tabular data source', $e->getMessage());
402400
}
403401
}
404-
};
402+
}
405403

406404
// write data to the new simple data source
407405
// you have to do this yourself, we don't support writing data stream at the moment
@@ -412,7 +410,7 @@ public function testCreateEditDatapackageDescriptor()
412410
$i = 0;
413411
foreach ($package->resource('my-default-resource') as $row) {
414412
if ($i == 0) {
415-
$this->assertEquals("foo", $row);
413+
$this->assertEquals('foo', $row);
416414
} elseif ($i == 1) {
417415
$this->assertEquals("testing 改善\n", $row);
418416
} elseif ($i == 2) {
@@ -437,78 +435,78 @@ public function testCreateEditDatapackageDescriptor()
437435
'name' => 'my-renamed-tabular-resource',
438436
'path' => [$tabularDataFilename],
439437
'profile' => 'tabular-data-resource',
440-
'schema' => (object)[
441-
"fields" => [
442-
(object)["name" => "id", "type" => "integer"],
443-
(object)["name" => "name", "type" => "string"]
444-
]
445-
]
438+
'schema' => (object) [
439+
'fields' => [
440+
(object) ['name' => 'id', 'type' => 'integer'],
441+
(object) ['name' => 'name', 'type' => 'string'],
442+
],
443+
],
446444
],
447445
],
448446
], json_decode(file_get_contents($filename)));
449447

450448
file_put_contents($tabularDataFilename, "id,name\n1,\"one\"\n2,\"two\"\n3,\"three\"");
451449
$this->assertEquals([
452-
["id" => 1, "name" => "one"],
453-
["id" => 2, "name" => "two"],
454-
["id" => 3, "name" => "three"]
455-
], $package->resource("my-renamed-tabular-resource")->read());
450+
['id' => 1, 'name' => 'one'],
451+
['id' => 2, 'name' => 'two'],
452+
['id' => 3, 'name' => 'three'],
453+
], $package->resource('my-renamed-tabular-resource')->read());
456454
}
457455

458456
public function testStringPath()
459457
{
460-
$package = Package::create(["resources" => [
461-
["name" => "_", "path" => dirname(__FILE__).'/fixtures/foo.txt']
458+
$package = Package::create(['resources' => [
459+
['name' => '_', 'path' => dirname(__FILE__).'/fixtures/foo.txt'],
462460
]]);
463-
$this->assertEquals(["foo"], $package->resource("_")->read());
461+
$this->assertEquals(['foo'], $package->resource('_')->read());
464462
}
465463

466464
public function testInlineDataRowArrays()
467465
{
468466
$resource = Resource::create([
469-
"name" => "_",
470-
"profile" => "tabular-data-resource",
471-
"schema" => [
472-
"fields" => [
473-
["name" => "id", "type" => "integer"],
474-
["name" => "name", "type" => "string"]
475-
]
467+
'name' => '_',
468+
'profile' => 'tabular-data-resource',
469+
'schema' => [
470+
'fields' => [
471+
['name' => 'id', 'type' => 'integer'],
472+
['name' => 'name', 'type' => 'string'],
473+
],
474+
],
475+
'data' => [
476+
['id', 'name'],
477+
[1, 'one'],
478+
[2, 'two'],
479+
[3, 'three'],
476480
],
477-
"data" => [
478-
["id", "name"],
479-
[1, "one"],
480-
[2, "two"],
481-
[3, "three"]
482-
]
483481
]);
484482
$this->assertEquals([
485-
["id" => 1, "name" => "one"],
486-
["id" => 2, "name" => "two"],
487-
["id" => 3, "name" => "three"]
483+
['id' => 1, 'name' => 'one'],
484+
['id' => 2, 'name' => 'two'],
485+
['id' => 3, 'name' => 'three'],
488486
], $resource->read());
489487
}
490488

491489
public function testInlineDataRowObjects()
492490
{
493491
$resource = Resource::create([
494-
"name" => "_",
495-
"profile" => "tabular-data-resource",
496-
"schema" => [
497-
"fields" => [
498-
["name" => "id", "type" => "integer"],
499-
["name" => "name", "type" => "string"]
500-
]
492+
'name' => '_',
493+
'profile' => 'tabular-data-resource',
494+
'schema' => [
495+
'fields' => [
496+
['name' => 'id', 'type' => 'integer'],
497+
['name' => 'name', 'type' => 'string'],
498+
],
499+
],
500+
'data' => [
501+
['id' => 1, 'name' => 'one'],
502+
['id' => 2, 'name' => 'two'],
503+
['id' => 3, 'name' => 'three'],
501504
],
502-
"data" => [
503-
["id" => 1, "name" => "one"],
504-
["id" => 2, "name" => "two"],
505-
["id" => 3, "name" => "three"]
506-
]
507505
]);
508506
$this->assertEquals([
509-
["id" => 1, "name" => "one"],
510-
["id" => 2, "name" => "two"],
511-
["id" => 3, "name" => "three"]
507+
['id' => 1, 'name' => 'one'],
508+
['id' => 2, 'name' => 'two'],
509+
['id' => 3, 'name' => 'three'],
512510
], $resource->read());
513511
}
514512

tests/Mocks/MockResource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66

77
class MockResource
88
{
9-
109
public static function load($descriptor, $basePath = null)
1110
{
1211
$descriptor = Utils::objectify($descriptor);
12+
1313
return MockFactory::resource($descriptor, $basePath);
1414
}
1515

1616
public static function create($descriptor, $basePath = null)
1717
{
1818
$descriptor = Utils::objectify($descriptor);
1919
$skipValidations = true;
20+
2021
return MockFactory::resource($descriptor, $basePath, $skipValidations);
2122
}
22-
2323
}

0 commit comments

Comments
 (0)