Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #5 from artesaos/analysis-z94Glq
Browse files Browse the repository at this point in the history
Applied fixes from StyleCI
  • Loading branch information
vinicius73 committed Jan 13, 2016
2 parents 61c0839 + 4509f04 commit 9157d33
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 60 deletions.
6 changes: 3 additions & 3 deletions resources/config/warehouse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

return [
'fractal' => [
'serializer' => null
]
];
'serializer' => null,
],
];
2 changes: 1 addition & 1 deletion src/AbstractCrudRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Artesaos\Warehouse\Contracts\Segregated\CrudRepository;
use Artesaos\Warehouse\Traits\CrudMethods;

abstract class AbstractCrudRepository extends BaseRepository implements CrudRepository
abstract class AbstractCrudRepository extends BaseRepository implements CrudRepository
{
use CrudMethods;
}
8 changes: 4 additions & 4 deletions src/BaseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

use Artesaos\Warehouse\Contracts\BaseRepository as BaseRepositoryContract;
use Illuminate\Database\Eloquent\Builder as EloquentQueryBuilder;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Pagination\AbstractPaginator as Paginator;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Pagination\AbstractPaginator as Paginator;

abstract class BaseRepository implements BaseRepositoryContract
{
Expand Down Expand Up @@ -66,7 +66,7 @@ public function getAll($take = 15, $paginate = true)
}

/**
* @param string $column
* @param string $column
* @param string|null $key
*
* @return \Illuminate\Support\Collection|array
Expand All @@ -80,7 +80,7 @@ public function lists($column, $key = null)
* Retrieves a record by his id
* If fail is true $ fires ModelNotFoundException.
*
* @param int $id
* @param int $id
* @param bool $fail
*
* @return Model
Expand Down
6 changes: 3 additions & 3 deletions src/Contracts/BaseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Artesaos\Warehouse\Contracts;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Pagination\AbstractPaginator as Paginator;

interface BaseRepository
Expand All @@ -24,15 +24,15 @@ public function getAll($take = 15, $paginate = true);
* Retrieves a record by his id
* If $fail is true fires ModelNotFoundException. When no record is found.
*
* @param int $id
* @param int $id
* @param bool $fail
*
* @return Model
*/
public function findByID($id, $fail = true);

/**
* @param string $column
* @param string $column
* @param string|null $key
*
* @return \Illuminate\Support\Collection|array
Expand Down
14 changes: 7 additions & 7 deletions src/Contracts/FractalFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
interface FractalFactory
{
/**
* @param ArrayAccess $collection
* @param array $meta
* @param ArrayAccess $collection
* @param array $meta
* @param TransformerAbstract|null $transformer
*
* @return \Illuminate\Http\JsonResponse
*/
public function makeCollectionResponse(ArrayAccess $collection, array $meta = array(), TransformerAbstract $transformer = null);
public function makeCollectionResponse(ArrayAccess $collection, array $meta = [], TransformerAbstract $transformer = null);

/**
* @param ArrayAccess $item
* @param array $meta
* @param ArrayAccess $item
* @param array $meta
* @param TransformerAbstract|null $transformer
*
* @return \Illuminate\Http\JsonResponse
Expand All @@ -30,12 +30,12 @@ public function makeItemResponse(ArrayAccess $item, array $meta = [], Transforme
*
* @return \Illuminate\Http\JsonResponse
*/
public function makeEmptyResponse(array $meta = array());
public function makeEmptyResponse(array $meta = []);

/**
* @param string $key
*
* @return array
*/
public function getRequestIncludes($key = 'include');
}
}
3 changes: 3 additions & 0 deletions src/Contracts/Segregated/CrudRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface CrudRepository
* @return Model
*/
public function create(array $data = []);

/**
* Updated model data, using $data
* The sequence performs the Model update.
Expand All @@ -24,6 +25,7 @@ public function create(array $data = []);
* @return bool
*/
public function update($model, array $data = []);

/**
* Performs the save method of the model
* The goal is to enable the implementation of your business logic before the command.
Expand All @@ -33,6 +35,7 @@ public function update($model, array $data = []);
* @return bool
*/
public function save($model);

/**
* Run the delete command model.
* The goal is to enable the implementation of your business logic before the command.
Expand Down
10 changes: 5 additions & 5 deletions src/Contracts/Segregated/FractalAvailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ interface FractalAvailable
{
/**
* @param Model|Arrayable $item
* @param array $meta
* @param array $meta
*
* @return \Illuminate\Http\JsonResponse
*/
public function makeResponseItem($item, $meta = array());
public function makeResponseItem($item, $meta = []);

/**
* @param \Illuminate\Database\Eloquent\Collection $collection
* @param array $meta
* @param array $meta
*
* @return \Illuminate\Http\JsonResponse
*/
public function makeResponseCollection($collection, $meta = array());
}
public function makeResponseCollection($collection, $meta = []);
}
54 changes: 30 additions & 24 deletions src/Fractal/FractalFactory.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
<?php
<?php


namespace Artesaos\Warehouse\Fractal;

use ArrayAccess;
use Artesaos\Warehouse\Contracts\FractalFactory as FractalFactoryContract;
use Artesaos\Warehouse\Fractal\Transformers\GenericTransformer;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Contracts\Routing\ResponseFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use League\Fractal\Manager as LeagueFractalFactory;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item as FractalItem;
use League\Fractal\Resource\ResourceAbstract;
use League\Fractal\TransformerAbstract;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class FractalFactory implements FractalFactoryContract
{
Expand All @@ -42,8 +43,8 @@ class FractalFactory implements FractalFactoryContract
/**
* FractalFactory constructor.
*
* @param Request $request
* @param Container $app
* @param Request $request
* @param Container $app
* @param ResponseFactory $response
*/
public function __construct(Request $request, Container $app, ResponseFactory $response)
Expand All @@ -60,7 +61,7 @@ public function __construct(Request $request, Container $app, ResponseFactory $r
*/
protected function isPaged($collection)
{
return (is_a($collection, \Illuminate\Contracts\Pagination\LengthAwarePaginator::class));
return is_a($collection, \Illuminate\Contracts\Pagination\LengthAwarePaginator::class);
}

/**
Expand Down Expand Up @@ -93,20 +94,20 @@ protected function getFractalFactory()
if (!$this->fractal):
$this->fractal = new LeagueFractalFactory();

$serializer = $this->app['config']->get('warehouse.fractal.serializer', null);
$serializer = $this->app['config']->get('warehouse.fractal.serializer', null);

if(!empty($serializer)) {
$this->fractal->setSerializer($this->app->make($serializer));
}
if (!empty($serializer)) {
$this->fractal->setSerializer($this->app->make($serializer));
}
endif;

return $this->fractal;
}

/**
* @param ResourceAbstract $resource
* @param string $key
* @param string|null $value
* @param string $key
* @param string|null $value
*
* @return void
*/
Expand All @@ -115,8 +116,7 @@ protected function addFractalMeta(ResourceAbstract $resource, $key, $value = nul
if (is_array($key)):
foreach ($key as $k => $v):
$resource->setMetaValue($k, $v);
endforeach;
else:
endforeach; else:
$resource->setMetaValue($key, $value);
endif;
}
Expand All @@ -142,7 +142,9 @@ public function getRequestIncludes($key = 'include')
{
$include = $this->request->get($key, '');

if (empty($include)) return [];
if (empty($include)) {
return [];
}

$include = explode(',', $include);

Expand All @@ -156,7 +158,9 @@ protected function loadFractalIncludes()
{
$include = $this->getRequestIncludes();

if (!empty($include)) $this->getFractalFactory()->parseIncludes($include);
if (!empty($include)) {
$this->getFractalFactory()->parseIncludes($include);
}
}

/**
Expand All @@ -165,7 +169,9 @@ protected function loadFractalIncludes()
*/
protected function modelIncludes($item, $include)
{
if ($item instanceof Model) $item->load($include);
if ($item instanceof Model) {
$item->load($include);
}
}

/**
Expand All @@ -192,7 +198,7 @@ protected function getTransformer(TransformerAbstract $transformer = null)
*
* @return \Illuminate\Http\JsonResponse
*/
public function makeEmptyResponse(array $metas = array())
public function makeEmptyResponse(array $metas = [])
{
$resource = $this->makeFractalItem([], $this->getTransformer());

Expand Down Expand Up @@ -224,13 +230,13 @@ public function makeItemResponse(ArrayAccess $item, array $meta = [], Transforme
}

/**
* @param ArrayAccess $collection
* @param array $meta
* @param ArrayAccess $collection
* @param array $meta
* @param TransformerAbstract|null $transformer
*
* @return \Illuminate\Http\JsonResponse
*/
public function makeCollectionResponse(ArrayAccess $collection, array $meta = array(), TransformerAbstract $transformer = null)
public function makeCollectionResponse(ArrayAccess $collection, array $meta = [], TransformerAbstract $transformer = null)
{
$this->loadFractalIncludes();

Expand All @@ -241,12 +247,12 @@ public function makeCollectionResponse(ArrayAccess $collection, array $meta = ar
$collection = $collection->getIterator();
$resource = $this->makeFractalCollection($collection, $this->getTransformer($transformer));
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
}else {
} else {
$resource = $this->makeFractalCollection($collection, $this->getTransformer($transformer));
}

$this->addFractalMeta($resource, $meta);

return $this->responseFractal($resource);
}
}
}
4 changes: 2 additions & 2 deletions src/Fractal/Transformers/GenericTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public function transform($data)
if (is_object($data)):
if ($data instanceof Arrayable):
return $data->toArray();
endif;
endif;
endif;

return (array) $data;
}
}
}
2 changes: 1 addition & 1 deletion src/Traits/CrudMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function factory(array $data = [])

return $model;
}

/**
* @param Model $model
* @param array $data
Expand Down
7 changes: 3 additions & 4 deletions src/Traits/ImplementsFractal.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Artesaos\Warehouse\Traits;

use Artesaos\Warehouse\Contracts\FractalFactory;

use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
Expand All @@ -25,7 +24,7 @@ protected function getFractalFactory()
*
* @return \Illuminate\Http\JsonResponse
*/
public function makeResponseItem($item, $meta = array())
public function makeResponseItem($item, $meta = [])
{
return $this->getFractalFactory()->makeItemResponse($item, $meta, $this->getTransformer());
}
Expand All @@ -36,7 +35,7 @@ public function makeResponseItem($item, $meta = array())
*
* @return \Illuminate\Http\JsonResponse
*/
public function makeResponseCollection($collection, $meta = array())
public function makeResponseCollection($collection, $meta = [])
{
return $this->getFractalFactory()->makeCollectionResponse($collection, $meta, $this->getTransformer());
}
Expand All @@ -48,4 +47,4 @@ protected function getTransformer()
{
return app($this->transformerClass);
}
}
}
Loading

0 comments on commit 9157d33

Please sign in to comment.