Skip to content

Commit ae0f550

Browse files
committed
fixes && cleanup
1 parent ee7ad55 commit ae0f550

File tree

12 files changed

+46
-96
lines changed

12 files changed

+46
-96
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
vendor/
22
var/cache
33
\.php_cs\.cache
4-
4+
build/
55
\.env
66

77
composer\.lock

phpunit.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
<directory suffix="Test.php">./tests</directory>
1414
</testsuite>
1515
</testsuites>
16+
<filter>
17+
<whitelist processUncoveredFilesFromWhitelist="true">
18+
<directory suffix=".php">./src</directory>
19+
</whitelist>
20+
</filter>
1621
<php>
1722
<env name="APP_ENV" value="testing"/>
1823
</php>

src/Api/Concerns/ApiTransformerTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function setSelectedAttributes(array $selectedAttributes = [])
1717
return $this;
1818
}
1919

20-
public function getSelectedAttributes()
20+
public function getSelectedAttributes(): array
2121
{
2222
return $this->selectedAttributes;
2323
}
@@ -29,7 +29,7 @@ public function setAuthorizedAttributes(array $authorizedAttributes = [])
2929
return $this;
3030
}
3131

32-
public function getAuthorizedAttributes()
32+
public function getAuthorizedAttributes(): array
3333
{
3434
return $this->authorizedAttributes;
3535
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Railken\LaraOre\Api\Contracts;
4+
5+
interface TransformerContract
6+
{
7+
public function setSelectedAttributes(array $selectedAttributes = []);
8+
9+
public function getSelectedAttributes(): array;
10+
11+
public function setAuthorizedAttributes(array $authorizedAttributes = []);
12+
13+
public function getAuthorizedAttributes(): array;
14+
}

src/Api/Http/Controllers/Controller.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
66
use Illuminate\Foundation\Bus\DispatchesJobs;
77
use Illuminate\Foundation\Validation\ValidatesRequests;
8+
use Illuminate\Http\JsonResponse;
89
use Illuminate\Routing\Controller as BaseController;
910
use Illuminate\Support\Facades\Auth;
1011

@@ -25,7 +26,7 @@ class Controller extends BaseController
2526
*/
2627
public function response($data = [], $status = 200, $headers = [], $options = 0)
2728
{
28-
return response()->json($data, $status, $headers, $options);
29+
return new JsonResponse($data, $status, $headers, $options);
2930
}
3031

3132
/**

src/Api/Http/Controllers/RestController.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use Illuminate\Support\Facades\DB;
88
use League\Fractal;
99
use League\Fractal\Serializer\JsonApiSerializer;
10-
use League\Fractal\TransformerAbstract;
1110
use Railken\Bag;
11+
use Railken\LaraOre\Api\Contracts\TransformerContract;
1212
use Railken\Laravel\Manager\Contracts\EntityContract;
1313
use Railken\Laravel\Manager\Tokens;
1414

@@ -116,7 +116,7 @@ public function getFractalTransformer()
116116
return new $classTransformer();
117117
}
118118

119-
public function initializeFractalTransformer(TransformerAbstract $transformer, EntityContract $entity = null, Request $request)
119+
public function initializeFractalTransformer(TransformerContract $transformer, EntityContract $entity = null, Request $request)
120120
{
121121
if ($entity !== null) {
122122
$transformer->setSelectedAttributes($this->getSelectedAttributesByRequest($request));
@@ -131,7 +131,7 @@ public function getFractalManager(Request $request)
131131
$manager = new Fractal\Manager();
132132
$manager->setSerializer(new JsonApiSerializer());
133133

134-
if ($request->input('include')) {
134+
if ($request->input('include') !== null) {
135135
$manager->parseIncludes($request->input('include'));
136136
}
137137

@@ -140,16 +140,16 @@ public function getFractalManager(Request $request)
140140

141141
public function getSelectedAttributesByRequest(Request $request)
142142
{
143-
$select = collect(explode(',', $request->input('select', '')));
143+
$select = collect(explode(',', strval($request->input('select', ''))));
144144

145145
if ($select->count() > 0) {
146-
$select = $this->keys->selectable->filter(function ($attr) use ($select) {
146+
$select = $this->keys->get('selectable')->filter(function ($attr) use ($select) {
147147
return $select->contains($attr);
148148
});
149149
}
150150

151151
if ($select->count() == 0) {
152-
$select = $this->keys->selectable;
152+
$select = $this->keys->get('selectable');
153153
}
154154

155155
return $select->toArray();

src/Api/Http/Middleware/AdminMiddleware.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/Api/Http/Middleware/HandleErrorsMiddleware.php

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/Api/Support/Paginator.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@ public function paginate($total, $page = 1, $take = 10)
1717
{
1818
$take = (int) $take;
1919
$page = (int) $page;
20-
$take <= 0 && $take = 10;
21-
$page <= 0 && $page = 1;
20+
21+
if ($take <= 0) {
22+
$take = 10;
23+
}
24+
25+
if ($page <= 0) {
26+
$page = 1;
27+
}
28+
2229
$skip = ($page - 1) * $take;
2330
$last = $skip + $take;
2431
$first = $skip + 1;

src/Api/Support/Sorter.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,26 @@
22

33
namespace Railken\LaraOre\Api\Support;
44

5-
use Illuminate\Support\Collection;
6-
75
class Sorter
86
{
97
/**
108
* List of sorting values.
119
*
12-
* @var Collection
10+
* @var array
1311
*/
1412
protected $values;
1513

1614
/**
1715
* List of sorting keys.
1816
*
19-
* @var Collection
17+
* @var array
2018
*/
2119
protected $keys;
2220

23-
/**
24-
* Construct.
25-
*/
26-
public function __construct()
27-
{
28-
$this->values = new Collection();
29-
}
30-
3121
/**
3222
* Set keys.
3323
*
34-
* @param Collection $keys
24+
* @param array $keys
3525
*
3626
* @return $this
3727
*/
@@ -68,7 +58,7 @@ public function add($name, $direction)
6858
/**
6959
* Retrieve all sorting values.
7060
*
71-
* @return Collection
61+
* @return array
7262
*/
7363
public function get()
7464
{

0 commit comments

Comments
 (0)