Skip to content

Commit

Permalink
fix: PSR-2 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
esbenp committed Aug 22, 2015
1 parent a5a802b commit 8d09ee6
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ root = true
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
insert_final_newline = false
indent_style = space
indent_size = 4
15 changes: 7 additions & 8 deletions src/Architect.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use InvalidArgumentException;
use Illuminate\Support\Collection;

class Architect {

class Architect
{
private $modeResolvers = [];

/**
Expand All @@ -20,7 +20,7 @@ public function parseData($data, array $modes, $key = null)
{
$return = [];

uksort($modes, function($a, $b){
uksort($modes, function ($a, $b) {
return substr_count($b, '.')-substr_count($a, '.');
});

Expand Down Expand Up @@ -54,11 +54,11 @@ public function parseData($data, array $modes, $key = null)
private function parseCollection(array $modes, $collection, &$root, $fullPropertyPath = '')
{
if (is_array($collection)) {
foreach($collection as $i => $resource){
foreach ($collection as $i => $resource) {
$collection[$i] = $this->parseResource($modes, $resource, $root, $fullPropertyPath);
}
} elseif ($collection instanceof Collection) {
$collection = $collection->map(function($resource) use($modes, &$root, $fullPropertyPath){
$collection = $collection->map(function ($resource) use ($modes, &$root, $fullPropertyPath) {
return $this->parseResource($modes, $resource, $root, $fullPropertyPath);
});
}
Expand All @@ -76,7 +76,7 @@ private function parseCollection(array $modes, $collection, &$root, $fullPropert
*/
private function parseResource(array $modes, &$resource, &$root, $fullPropertyPath = '')
{
foreach($modes as $relation => $mode) {
foreach ($modes as $relation => $mode) {
$modeResolver = $this->resolveMode($mode);

$steps = explode('.', $relation);
Expand Down Expand Up @@ -143,7 +143,7 @@ private function resolveMode($mode)
private function createModeResolver($mode)
{
$class = 'Optimus\Architect\ModeResolver\\';
switch($mode){
switch ($mode) {
default:
case 'embed':
$class .= 'EmbedModeResolver';
Expand All @@ -158,5 +158,4 @@ private function createModeResolver($mode)

return new $class;
}

}
5 changes: 2 additions & 3 deletions src/ModeResolver/EmbedModeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Optimus\Architect\ModeResolver\ModeResolverInterface;

class EmbedModeResolver implements ModeResolverInterface {

class EmbedModeResolver implements ModeResolverInterface
{
/**
* Simply returns the object since embedded is the default
* transformation
Expand All @@ -19,5 +19,4 @@ public function resolve($property, &$object, &$root, $fullPropertyPath)
{
return $object;
}

}
11 changes: 5 additions & 6 deletions src/ModeResolver/IdsModeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use Optimus\Architect\ModeResolver\ModeResolverInterface;
use Optimus\Architect\Utility;

class IdsModeResolver implements ModeResolverInterface {

class IdsModeResolver implements ModeResolverInterface
{
/**
* Map through the collection and convert it to a collection
* of ids
Expand All @@ -20,14 +20,13 @@ class IdsModeResolver implements ModeResolverInterface {
public function resolve($property, &$object, &$root, $fullPropertyPath)
{
if (is_array($object)) {
return array_map(function($entry){
return array_map(function ($entry) {
return (int) Utility::getProperty($entry, 'id');
}, $object);
} elseif($object instanceof Collection) {
return $object->map(function($entry){
} elseif ($object instanceof Collection) {
return $object->map(function ($entry) {
return (int) Utility::getProperty($entry, 'id');
});
}
}

}
5 changes: 2 additions & 3 deletions src/ModeResolver/ModeResolverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace Optimus\Architect\ModeResolver;

interface ModeResolverInterface {

interface ModeResolverInterface
{
public function resolve($property, &$object, &$root, $fullPropertyPath);

}
18 changes: 9 additions & 9 deletions src/ModeResolver/SideloadModeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
use Optimus\Architect\ModeResolver\ModeResolverInterface;
use Optimus\Architect\Utility;

class SideloadModeResolver implements ModeResolverInterface {

class SideloadModeResolver implements ModeResolverInterface
{
private $idsResolver;

public function __construct(){
public function __construct()
{
$this->idsResolver = new IdsModeResolver;
}

Expand Down Expand Up @@ -57,11 +58,11 @@ private function addCollectionToRoot(&$root, &$object, $fullPropertyPath)
private function mergeRootCollection(&$collection, $object)
{
if (is_array($object)) {
foreach($object as $resource) {
foreach ($object as $resource) {
$this->addResourceToRootCollectionIfNonExistant($collection, $resource);
}
} elseif($object instanceof Collection) {
$object->each(function($resource) use(&$collection){
} elseif ($object instanceof Collection) {
$object->each(function ($resource) use (&$collection) {
$this->addResourceToRootCollectionIfNonExistant($collection, $resource);
});
}
Expand All @@ -80,7 +81,7 @@ private function addResourceToRootCollectionIfNonExistant(&$collection, $resourc

$copy = $collection instanceof Collection ? $collection->toArray() : $collection;

foreach($copy as $rootResource) {
foreach ($copy as $rootResource) {
if ((int) Utility::getProperty($rootResource, 'id') === (int) $identifier) {
$exists = true;
break;
Expand All @@ -90,10 +91,9 @@ private function addResourceToRootCollectionIfNonExistant(&$collection, $resourc
if ($exists === false) {
if (is_array($collection)) {
$collection[] = $resource;
} elseif($collection instanceof Collection) {
} elseif ($collection instanceof Collection) {
$collection->push($resource);
}
}
}

}
5 changes: 2 additions & 3 deletions src/Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Illuminate\Database\Eloquent\Model as EloquentModel;
use Illuminate\Support\Collection;

class Utility {

class Utility
{
/**
* Get a property of an array or object
* @param mixed $objectOrArray object or array
Expand Down Expand Up @@ -54,5 +54,4 @@ public static function isCollection($input)
{
return is_array($input) || $input instanceof Collection;
}

}
10 changes: 5 additions & 5 deletions tests/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

require_once __DIR__.'/Model/Resource.php';

class Controller {

class Controller
{
private $idCounts = [];

private $architect;

public function __construct(){
public function __construct()
{
$this->architect = new Architect;
}

Expand All @@ -36,7 +37,7 @@ private function createCollection($rows = 2, $children = false, $childrensChildr
}

$data = [];
for($i=1;$i<=$rows;$i++) {
for ($i=1;$i<=$rows;$i++) {
$this->idCounts[$level]++;

$tmp = [
Expand All @@ -54,5 +55,4 @@ private function createCollection($rows = 2, $children = false, $childrensChildr

return $array === true ? $data : Collection::make($data);
}

}
5 changes: 2 additions & 3 deletions tests/DatabaseTestCase.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

class DatabaseTestCase extends Orchestra\Testbench\TestCase {

class DatabaseTestCase extends Orchestra\Testbench\TestCase
{
protected function getEnvironmentSetUp($app)
{
$app['config']->set('database.default', 'tests');
Expand All @@ -11,5 +11,4 @@ protected function getEnvironmentSetUp($app)
'prefix' => ''
]);
}

}
5 changes: 2 additions & 3 deletions tests/ModeResolver/EmbedModeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
require_once __DIR__.'/../Controller.php';
require_once __DIR__.'/../DatabaseTestCase.php';

class EmbedModeResolverTest extends DatabaseTestCase {

class EmbedModeResolverTest extends DatabaseTestCase
{
public function testEmbedModeResolverOnVanillaCollections()
{
$controller = new Controller;
Expand Down Expand Up @@ -158,5 +158,4 @@ public function testEmbedModeResolverOnNestedChildrenOnEloquentCollections()
$second = $parsed->get(1)->children->get(0)->nestedChildren;
$this->assertEquals(3, $second->get(0)->id);
}

}
5 changes: 2 additions & 3 deletions tests/ModeResolver/IdsModeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
require_once __DIR__.'/../Controller.php';
require_once __DIR__.'/../DatabaseTestCase.php';

class IdsModeResolverTest extends DatabaseTestCase {

class IdsModeResolverTest extends DatabaseTestCase
{
public function testIdsModeResolverOnVanillaCollections()
{
$controller = new Controller;
Expand Down Expand Up @@ -129,5 +129,4 @@ public function testIdsModeResolverOnNestedChildrenOnEloquentCollections()
3
], $second);
}

}
4 changes: 2 additions & 2 deletions tests/ModeResolver/SideloadModeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
require_once __DIR__.'/../Controller.php';
require_once __DIR__.'/../DatabaseTestCase.php';

class SideloadModeResolverTest extends DatabaseTestCase {

class SideloadModeResolverTest extends DatabaseTestCase
{
public function testSideloadModeResolverOnVanillaCollections()
{
$controller = new Controller;
Expand Down
8 changes: 4 additions & 4 deletions tests/Model/Children.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

require_once __DIR__.'/NestedChildren.php';

class Children extends Model {

class Children extends Model
{
protected $table = 'children';

public function nestedChildren() {
public function nestedChildren()
{
return $this->hasMany('NestedChildren');
}

}
5 changes: 2 additions & 3 deletions tests/Model/NestedChildren.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

use Illuminate\Database\Eloquent\Model;

class NestedChildren extends Model {

class NestedChildren extends Model
{
protected $table = 'nested_children';

}
5 changes: 2 additions & 3 deletions tests/Model/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
require_once __DIR__.'/Children.php';
require_once __DIR__.'/SharedChildren.php';

class Resource extends Model {

class Resource extends Model
{
protected $table = 'resource';

public function children()
Expand All @@ -18,5 +18,4 @@ public function sharedChildren()
{
return $this->belongsToMany('SharedChildren', 'resource_shared_children', 'resource_id', 'shared_children_id');
}

}
5 changes: 2 additions & 3 deletions tests/Model/SharedChildren.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

use Illuminate\Database\Eloquent\Model;

class SharedChildren extends Model {

class SharedChildren extends Model
{
protected $table = 'shared_children';

}

0 comments on commit 8d09ee6

Please sign in to comment.