Skip to content

Commit

Permalink
Merge pull request #35 from GawainLynch/clean-up
Browse files Browse the repository at this point in the history
PSR-2, PSR-5, Bolt & Symfony clean up and unused imports
  • Loading branch information
Raistlfiren authored Dec 6, 2016
2 parents 18d313c + c856755 commit d62f564
Show file tree
Hide file tree
Showing 44 changed files with 198 additions and 148 deletions.
11 changes: 6 additions & 5 deletions src/Action/ContentListAction.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Bolt\Extension\Bolt\JsonApi\Action;

use Bolt\Extension\Bolt\JsonApi\Converter\Parameter\ParameterCollection;
Expand All @@ -11,14 +10,16 @@

/**
* Class ContentListAction
*
* @package Bolt\Extension\Bolt\JsonApi\Action
*/
class ContentListAction extends FetchAction
{
/**
* @param $contentType
* @param Request $request
* @param Request $request
* @param ParameterCollection $parameters
*
* @return ApiResponse
*/
public function handle($contentType, Request $request, ParameterCollection $parameters)
Expand All @@ -34,7 +35,7 @@ public function handle($contentType, Request $request, ParameterCollection $para

$results = $set->get($contentType);

$this->throwErrorOnNoResults($results, "Bad request: There were no results based upon your criteria!");
$this->throwErrorOnNoResults($results, 'Bad request: There were no results based upon your criteria!');

$this->fetchIncludes(
$parameters->getParametersByType('includes'),
Expand All @@ -58,8 +59,8 @@ public function handle($contentType, Request $request, ParameterCollection $para
$request
),
'meta' => [
"count" => count($items),
"total" => $set->getTotalResults()
'count' => count($items),
'total' => $set->getTotalResults(),
],
'data' => $items,
];
Expand Down
7 changes: 4 additions & 3 deletions src/Action/FetchAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ class FetchAction

/**
* FetchAction constructor.
* @param Query $query
* @param Parser $parser
*
* @param Query $query
* @param Parser $parser
* @param DataLinks $dataLinks
* @param Config $config
* @param Config $config
*/
public function __construct(
Query $query,
Expand Down
10 changes: 6 additions & 4 deletions src/Action/MenuAction.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Bolt\Extension\Bolt\JsonApi\Action;

use Bolt\Config;
Expand All @@ -10,6 +9,7 @@

/**
* Class MenuAction
*
* @package Bolt\Extension\Bolt\JsonApi\Action
*/
class MenuAction
Expand All @@ -22,7 +22,8 @@ class MenuAction

/**
* MenuAction constructor.
* @param Config $boltConfig
*
* @param Config $boltConfig
* @param \Bolt\Extension\Bolt\JsonApi\Config\Config $extensionConfig
*/
public function __construct(Config $boltConfig, \Bolt\Extension\Bolt\JsonApi\Config\Config $extensionConfig)
Expand All @@ -33,6 +34,7 @@ public function __construct(Config $boltConfig, \Bolt\Extension\Bolt\JsonApi\Con

/**
* @param Request $request
*
* @return ApiResponse
*/
public function handle(Request $request)
Expand All @@ -41,7 +43,7 @@ public function handle(Request $request)
$name = "/$name";
}

$menu = $this->boltConfig->get('menu'.$name, false);
$menu = $this->boltConfig->get('menu' . $name, false);

if (! $menu) {
throw new ApiNotFoundException(
Expand All @@ -50,7 +52,7 @@ public function handle(Request $request)
}

return new ApiResponse([
'data' => $menu
'data' => $menu,
], $this->extensionConfig);
}
}
13 changes: 7 additions & 6 deletions src/Action/SearchAction.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Bolt\Extension\Bolt\JsonApi\Action;

use Bolt\Extension\Bolt\JsonApi\Converter\Parameter\ParameterCollection;
Expand All @@ -11,14 +10,16 @@

/**
* Class SearchAction
*
* @package Bolt\Extension\Bolt\JsonApi\Action
*/
class SearchAction extends FetchAction
{
/**
* @param null $contentType
* @param Request $request
* @param null $contentType
* @param Request $request
* @param ParameterCollection $parameters
*
* @return ApiResponse
*/
public function handle($contentType = null, Request $request, ParameterCollection $parameters)
Expand All @@ -27,7 +28,7 @@ public function handle($contentType = null, Request $request, ParameterCollectio

if (! $search) {
throw new ApiInvalidRequestException(
"No query parameter q specified."
'No query parameter q specified.'
);
}

Expand Down Expand Up @@ -70,8 +71,8 @@ public function handle($contentType = null, Request $request, ParameterCollectio
$request
),
'meta' => [
"count" => count($items),
"total" => $set->getTotalResults()
'count' => count($items),
'total' => $set->getTotalResults(),
],
'data' => $items,
], $this->config);
Expand Down
17 changes: 9 additions & 8 deletions src/Action/SingleAction.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Bolt\Extension\Bolt\JsonApi\Action;

use Bolt\Extension\Bolt\JsonApi\Converter\Parameter\ParameterCollection;
Expand All @@ -11,6 +10,7 @@

/**
* Class SingleAction
*
* @package Bolt\Extension\Bolt\JsonApi\Action
*/
class SingleAction extends FetchAction
Expand All @@ -19,8 +19,9 @@ class SingleAction extends FetchAction
* @param $contentType
* @param $slug
* @param $relatedContentType
* @param Request $request
* @param Request $request
* @param ParameterCollection $parameters
*
* @return array|ApiResponse
*/
public function handle($contentType, $slug, $relatedContentType, Request $request, ParameterCollection $parameters)
Expand Down Expand Up @@ -62,13 +63,13 @@ public function handle($contentType, $slug, $relatedContentType, Request $reques
'links' => [
'self' => $this->config->getBasePath() .
"/$contentType/$slug/$relatedContentType" .
$this->dataLinks->makeQueryParameters($request->query->all())
$this->dataLinks->makeQueryParameters($request->query->all()),
],
'meta' => [
"count" => count($items),
"total" => count($items)
'count' => count($items),
'total' => count($items),
],
'data' => $items
'data' => $items,
], $this->config);
} else {
//$allFields = $this->APIHelper->getAllFieldNames($contentType);
Expand All @@ -81,7 +82,7 @@ public function handle($contentType, $slug, $relatedContentType, Request $reques

$defaultQueryString = $this->dataLinks->makeQueryParameters($request->query->all());
$links = [
'self' => $values['links']['self'] . $defaultQueryString
'self' => $values['links']['self'] . $defaultQueryString,
];

// optional: This adds additional relationships links in the root
Expand Down Expand Up @@ -118,7 +119,7 @@ public function handle($contentType, $slug, $relatedContentType, Request $reques

$response = [
'links' => $links,
'data' => $values,
'data' => $values,
];

if (!empty($included)) {
Expand Down
7 changes: 5 additions & 2 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@

class Config
{

/**
* @var string
*/
private $base = "/json";
private $base = '/json';

/**
* @var string
Expand Down Expand Up @@ -258,6 +257,7 @@ public function setJsonOptions($jsonOptions)

/**
* @param $contentType
*
* @return array
*/
public function getWhereClauses($contentType)
Expand All @@ -271,6 +271,7 @@ public function getWhereClauses($contentType)

/**
* @param $contentType
*
* @return array
*/
public function getListFields($contentType)
Expand All @@ -284,6 +285,7 @@ public function getListFields($contentType)

/**
* @param $contentType
*
* @return array
*/
public function getItemFields($contentType)
Expand All @@ -297,6 +299,7 @@ public function getItemFields($contentType)

/**
* @param $contentType
*
* @return array
*/
public function getAllowedFields($contentType)
Expand Down
19 changes: 7 additions & 12 deletions src/Controllers/ContentController.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
<?php
namespace Bolt\Extension\Bolt\JsonApi\Controllers;

use Bolt\Content;
use Bolt\Extension\Bolt\JsonApi\Config\Config;
use Bolt\Extension\Bolt\JsonApi\Exception\ApiNotFoundException;
use Bolt\Extension\Bolt\JsonApi\Response\ApiInvalidRequestResponse;
use Bolt\Extension\Bolt\JsonApi\Response\ApiNotFoundResponse;
use Bolt\Extension\Bolt\JsonApi\Response\ApiResponse;
use Silex\Application;
use Silex\ControllerCollection;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

/**
* Class ContentController
*
* @package JSONAPI\Controllers
*/
class ContentController implements ControllerProviderInterface
Expand All @@ -26,6 +20,7 @@ class ContentController implements ControllerProviderInterface

/**
* ContentController constructor.
*
* @param Config $config
*/
public function __construct(Config $config)
Expand All @@ -47,24 +42,24 @@ public function connect(Application $app)
*/
$ctr = $app['controllers_factory'];

$ctr->get("/menu", [$app['jsonapi.action.menu'], "handle"])
$ctr->get('/menu', [$app['jsonapi.action.menu'], 'handle'])
->bind('jsonapi.menu');

$ctr->get("/search", [$app['jsonapi.action.search'], "handle"])
$ctr->get('/search', [$app['jsonapi.action.search'], 'handle'])
->bind('jsonapi.searchAll')
->convert('parameters', 'jsonapi.converter:grabParameters');

$ctr->get("/{contentType}/search", [$app['jsonapi.action.search'], "handle"])
$ctr->get('/{contentType}/search', [$app['jsonapi.action.search'], 'handle'])
->bind('jsonapi.searchContent')
->convert('parameters', 'jsonapi.converter:grabParameters');

$ctr->get("/{contentType}/{slug}/{relatedContentType}", [$app['jsonapi.action.single'], 'handle'])
$ctr->get('/{contentType}/{slug}/{relatedContentType}', [$app['jsonapi.action.single'], 'handle'])
->value('relatedContentType', null)
->assert('slug', '[a-zA-Z0-9_\-]+')
->bind('jsonapi.singleContent')
->convert('parameters', 'jsonapi.converter:grabParameters');

$ctr->get("/{contentType}", [$app['jsonapi.action.contentlist'], "handle"])
$ctr->get('/{contentType}', [$app['jsonapi.action.contentlist'], 'handle'])
->bind('jsonapi.listContent')
->convert('parameters', 'jsonapi.converter:grabParameters');

Expand Down
11 changes: 6 additions & 5 deletions src/Converter/JSONAPIConverter.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
<?php


namespace Bolt\Extension\Bolt\JsonApi\Converter;

use Bolt\Extension\Bolt\JsonApi\Config\Config;
use Bolt\Extension\Bolt\JsonApi\Converter\Parameter\ParameterFactory;
use Bolt\Extension\Bolt\JsonApi\Converter\Parameter\ParameterInterface;
use Bolt\Extension\Bolt\JsonApi\Response\ApiInvalidRequestResponse;
use Bolt\Extension\Bolt\JsonApi\Response\ApiNotFoundResponse;
use Bolt\Storage\Mapping\MetadataDriver;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\HttpFoundation\Request;

/**
* Class JSONAPIConverter
*
* @package Bolt\Extension\Bolt\JsonApi\Converter
*/
class JSONAPIConverter
{

/** @var Config $config */
protected $config;

Expand All @@ -27,7 +24,8 @@ class JSONAPIConverter

/**
* JSONAPIConverter constructor.
* @param Config $config
*
* @param Config $config
* @param MetadataDriver $metadata
*/
public function __construct(Config $config, MetadataDriver $metadata)
Expand All @@ -38,8 +36,10 @@ public function __construct(Config $config, MetadataDriver $metadata)

/**
* Create an array of parameters to be handled by our ParameterFactory class
*
* @param $converter
* @param Request $request
*
* @return Collection|ParameterInterface[]
*/
public function grabParameters($converter, Request $request)
Expand Down Expand Up @@ -72,6 +72,7 @@ public function grabParameters($converter, Request $request)

/**
* @param $parameters
*
* @return mixed
*/
protected function isSearch($parameters)
Expand Down
Loading

0 comments on commit d62f564

Please sign in to comment.