Skip to content

Commit

Permalink
Applies php-cs-fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Manderson committed Sep 23, 2014
1 parent f5e1a68 commit 532b6fc
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ protected function isCancelled(\Symfony\Component\HttpFoundation\Request $reques
*/
protected function saveErrors(\Symfony\Component\HttpFoundation\Request $request, $errors)
{
if(!empty($errors) && !($errors instanceof \Phruts\Action\ActionErrors)) {
if (!empty($errors) && !($errors instanceof \Phruts\Action\ActionErrors)) {
throw new \Phruts\Exception\IllegalArgumentException('Errors should be an \Phruts\Action\ActionErrors object');
}

Expand Down
52 changes: 29 additions & 23 deletions src/Action/ActionKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public function __construct(\Silex\Application $application)
* and do its best to convert them to a Response instance.
*
* @param Request $request A Request instance
* @param int $type The type of the request
* (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST)
* @param bool $catch Whether to catch exceptions or not
* @param int $type The type of the request
* (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST)
* @param bool $catch Whether to catch exceptions or not
*
* @return Response A Response instance
*
Expand All @@ -62,8 +62,9 @@ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch =
try {
$response = new Response();
$this->process($request, $response);

return $response;
} catch(\Exception $e) {
} catch (\Exception $e) {
if (false === $catch) {
throw $e;
}
Expand All @@ -74,24 +75,25 @@ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch =
}

/**
* @param \Exception $e
* @param Request $request
* @param \Exception $e
* @param Request $request
* @param $type
* @return Response
*/
protected function handleException(\Exception $e, Request $request, $type)
{
// Handle exception using internal messaging?
if(!empty($this->log)) {
if (!empty($this->log)) {
$this->log->error($e->getMessage());
}
$response = new Response($this->getInternal()->getMessage(null, 'actionKernel.exception'), 501);

return $response;
}

/**
*
* @param Request $request
* @param Request $request
* @param Response $response
*/
protected function process(Request $request, Response $response)
Expand All @@ -100,31 +102,31 @@ protected function process(Request $request, Response $response)
$this->getRequestProcessor($this->getModuleConfig($request))->process($request, $response);
}


/**
* Initialise the module configurations
* @throws \Phruts\Exception
*/
protected function init() {
protected function init()
{
// Initialise once
if($this->init) return;

$prefixes = array();

// Obtain the module config provider (implements caching, etc)
if(empty($this->application[\Phruts\Util\Globals::MODULE_CONFIG_PROVIDER])) {
if (empty($this->application[\Phruts\Util\Globals::MODULE_CONFIG_PROVIDER])) {
throw new \Phruts\Exception($this->getInternal()->getMessage('', 'moduleConfig.provider.missing'));
}
$moduleConfigProvider = $this->application[\Phruts\Util\Globals::MODULE_CONFIG_PROVIDER];

// Get the configured modules
foreach($this->application[\Phruts\Util\Globals::ACTION_KERNEL_CONFIG] as $prefixParam => $config) {
foreach ($this->application[\Phruts\Util\Globals::ACTION_KERNEL_CONFIG] as $prefixParam => $config) {
if(strlen($prefixParam) > 7 && substr($prefixParam, 0, 7) == 'config/') continue;
$prefix = substr($prefixParam, 7);

// Get the module config
$moduleConfig = $moduleConfigProvider->getModuleConfig($prefix, $config);
if(empty($moduleConfig)) {
if (empty($moduleConfig)) {
throw new \Phruts\Exception($this->getInternal()->getMessage('', 'moduleConfig.missing', $prefix));
}
$this->application[\Phruts\Util\Globals::MODULE_KEY . $prefix] = $moduleConfig;
Expand All @@ -139,25 +141,27 @@ protected function init() {
$this->application[\Phruts\Util\Globals::PREFIXES_KEY] = $prefixes;

$this->init = true;

return;
}

/**
* @param Request $request
* @param Request $request
* @return \Phruts\Config\ModuleConfig
*/
protected function getModuleConfig(Request $request) {
protected function getModuleConfig(Request $request)
{
$config = $request->attributes->get(\Phruts\Util\Globals::MODULE_KEY);
if (empty($config)) {
if(empty($this->application[\Phruts\Util\Globals::MODULE_KEY])) {
if (empty($this->application[\Phruts\Util\Globals::MODULE_KEY])) {
throw new \Phruts\Exception($this->getInternal()->getMessage('', 'moduleConfig.missing.default'));
}
$config = $this->application[\Phruts\Util\Globals::MODULE_KEY];
}

return $config;
}


/**
* Instantiate the request processor if defined in the config
* @param \Phruts\Config\ModuleConfig $config
Expand All @@ -177,6 +181,7 @@ protected function getRequestProcessor(\Phruts\Config\ModuleConfig $config)

$processor->init($this, $config);
$this->application[$key] = $processor;

return $this->application[$key];
} catch (\Exception $e) {
throw new \Exception('Cannot initialize RequestProcessor of class ' . $processorClass . ': ' . $e->getMessage());
Expand All @@ -200,7 +205,7 @@ protected function initModuleMessageResources(\Phruts\Config\ModuleConfig $confi
$factoryObject = \Phruts\Util\MessageResourcesFactory::createFactory($factory);
if (is_null($factoryObject)) {
$msg = 'Cannot load resources from "' . $mrc->getParameter() . '"';
if(!empty($this->log)) {
if (!empty($this->log)) {
$this->log->error($msg);
}
throw new \Phruts\Exception($msg);
Expand Down Expand Up @@ -230,7 +235,7 @@ protected function initModuleDataSources(\Phruts\Config\ModuleConfig $config)
$dsFactory = \Phruts\Util\DataSourceFactory::createFactory($dsc);
} catch (\Exception $e) {
$msg = $this->getInternal()->getMessage(null, 'dataSource.init', $dsc->getKey());
if(!empty($this->log)) {
if (!empty($this->log)) {
$this->log->error($msg . ' - ' . $e->getMessage());
}
throw new \Phruts\Exception($msg);
Expand Down Expand Up @@ -260,7 +265,7 @@ protected function initModulePlugIns(\Phruts\Config\ModuleConfig $config)
$plugIns[] = $plugIn;
} catch (\Exception $e) {
$msg = $this->getInternal()->getMessage(null, 'plugIn.init', $plugInConfig->getClassName());
if(!empty($this->log)) {
if (!empty($this->log)) {
$this->log->error($msg . ' - ' . $e->getMessage());
}
throw new \Phruts\Exception($msg);
Expand All @@ -273,12 +278,13 @@ protected function initModulePlugIns(\Phruts\Config\ModuleConfig $config)
* Use for messaging
* @return \Phruts\Util\MessageResources
*/
public function getInternal() {
public function getInternal()
{
return new PropertyMessageResources(__DIR__ . '/ActionResources');
}

/**
* @param Request $request
* @param Request $request
* @param $key
* @return \Phruts\
*/
Expand All @@ -303,6 +309,7 @@ public function getDataSource(Request $request, $key)
}
$request->attributes->set($keyPrefixed, $dataSource);
}

return $dataSource;
}

Expand All @@ -322,5 +329,4 @@ public function getApplication()
return $this->application;
}


}
3 changes: 2 additions & 1 deletion src/Action/ActionMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function getInputForward()
{
$controllerInputForward = null;
$controllerConfig = $this->getModuleConfig()->getControllerConfig();
if(!empty($controllerConfig)) {
if (!empty($controllerConfig)) {
$controllerInputForward = $controllerConfig->getInputForward();
}

Expand All @@ -92,6 +92,7 @@ public function getInputForward()
} else {
$forward = new \Phruts\Config\ForwardConfig();
$forward->setPath($this->getInput());

return $forward;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Action/ActionMessageItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ActionMessageItem
protected $iOrder = 0;

/**
* @param array $list The list of ActionMessages.
* @param array $list The list of ActionMessages.
* @param integer $iOrder The position in the list of messages.
*/
public function __construct(array $list, $iOrder)
Expand Down
13 changes: 6 additions & 7 deletions src/Action/RequestProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function init(\Phruts\Action\ActionKernel $actionKernel, \Phruts\Config\M

// Log
$application = $this->actionKernel->getApplication();
if(!empty($application['logger'])) {
if (!empty($application['logger'])) {
$this->log = $application['logger'];
}
}
Expand Down Expand Up @@ -193,7 +193,7 @@ protected function processPath(\Symfony\Component\HttpFoundation\Request $reques
$prefix = $this->moduleConfig->getPrefix();
if (substr($path, 0, strlen($prefix)) != $prefix) {
$msg = $this->getInternal()->getMessage("processPath", $request->getRequestURI());
if(!empty($this->log)) {
if (!empty($this->log)) {
$this->log->error($msg);
}
throw new BadRequestHttpException($msg);
Expand Down Expand Up @@ -377,13 +377,13 @@ protected function processMapping(\Symfony\Component\HttpFoundation\Request $req

// No mapping can be found to process this request
$internal = $this->getInternal();
if(!empty($internal)) {
if (!empty($internal)) {
$msg = $this->getInternal()->getMessage(null, 'processInvalid', $path);
} else {
$msg = 'processInvalid';
}

if(!empty($this->log)) {
if (!empty($this->log)) {
$this->log->error($msg);
}
throw new BadRequestHttpException($msg);
Expand Down Expand Up @@ -413,7 +413,7 @@ protected function processRoles(\Symfony\Component\HttpFoundation\Request $reque
}

// Check the current user against the list of required roles
if(!empty($app['security'])) {
if (!empty($app['security'])) {
$security = $app['security'];

foreach ($roles as $role) {
Expand All @@ -432,7 +432,6 @@ protected function processRoles(\Symfony\Component\HttpFoundation\Request $reque
}
}


// The current user is not authorized for this action
if (!empty($this->log)) {
$this->log->debug(' User does not have any required role, denying access');
Expand Down Expand Up @@ -697,7 +696,7 @@ protected function processActionCreate(\Symfony\Component\HttpFoundation\Request
$instance = \Phruts\Util\ClassLoader::newInstance($className, '\Phruts\Action');
} catch (\Exception $e) {
$msg = $this->getInternal()->getMessage(null, 'actionCreate', $mapping->getPath());
if(!empty($this->log)) {
if (!empty($this->log)) {
$this->log->error($msg . ' - ' . $e->getMessage());
}
throw new HttpException(500, $msg);
Expand Down
2 changes: 1 addition & 1 deletion src/Actions/ActionDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected function dispatchMethod(\Phruts\Config\ActionConfig $mapping, \Phruts\
// Identify the method object to be dispatched to
$reflectionClass = new \ReflectionClass(get_class($this));
$method = null;
if($reflectionClass->hasMethod($name)) {
if ($reflectionClass->hasMethod($name)) {
$method = $reflectionClass->getMethod($name);
}

Expand Down
11 changes: 7 additions & 4 deletions src/Actions/ForwardAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

use Phruts\Config\ForwardConfig;

class ForwardAction extends \Phruts\Action {
class ForwardAction extends \Phruts\Action
{
public function execute(
\Phruts\Config\ActionConfig $mapping,
\Phruts\Action\AbstractActionForm $form = null,
Expand All @@ -14,22 +15,24 @@ public function execute(

// Action Config defines the parameter for the forward configuration
$parameter = $mapping->getParameter();
if(empty($parameter)) {
if (empty($parameter)) {
throw new \Phruts\Exception\IllegalArgumentException('Need to specify a parameter for this ForwardAction');
}

// Original strategy, let's assume it is a path
if(!preg_match('/^[A-z]+$/', $parameter)) {
if (!preg_match('/^[A-z]+$/', $parameter)) {
$forward = new ForwardConfig();
$forward->setPath($parameter);
$forward->setContextRelative(true);

return $forward;
} else {
// Forward the request
$forward = $mapping->findForwardConfig($parameter);
if(empty($forward)) {
if (empty($forward)) {
throw new \Phruts\Exception('ForwardAction parameter should reference a forward config name');
}

return $forward;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/Actions/LookupDispatchAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

namespace Phruts\Actions;


class LookupDispatchAction extends \Phruts\Action {}
2 changes: 1 addition & 1 deletion src/Config/ActionConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ public function removeExceptionConfig(\Phruts\Config\ExceptionConfig $config)
* Return the exception configuration for the specified type, if any;
* otherwise return <code>null</code>.
* @return \Phruts\Config\ExceptionConfig
* @param string $type class name to find a configuration for
* @param string $type class name to find a configuration for
*/
public function findExceptionConfig($type)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Config/ConfigRuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct($configPrefix = 'phruts-config')
* pushed onto the evaluation stack before parsing begins.
*
* @param \Phigester\Digester $digester Digester instance to which the
* new Rule instances should be added.
* new Rule instances should be added.
*/
public function addRuleInstances(\Phigester\Digester $digester)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Util/BeanUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function populate($bean, array $properties)
$propertySetter = 'set' . ucfirst($name);
if (method_exists($bean, $propertySetter)) {
$reflectionMethod = $reflection->getMethod($propertySetter);
if(!empty($reflectionMethod) && $reflectionMethod->isPublic()) {
if (!empty($reflectionMethod) && $reflectionMethod->isPublic()) {
$bean->$propertySetter($value);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Util/MessageResources.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function getMessage($locale, $key, $arg0 = null, $arg1 = null, $arg2 = nu
* for the system default Locale
* @param string $key The message key to look up
*/
protected abstract function getBaseMessage($locale, $key);
abstract protected function getBaseMessage($locale, $key);

/**
* Return true if there is a defined message for the specified key
Expand Down
6 changes: 3 additions & 3 deletions src/Util/TokenProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public static function getInstance()
return $instance;
}

private function __construct() {

}
private function __construct()
{
}

/**
* The timestamp used most recently to generate a token value.
Expand Down

0 comments on commit 532b6fc

Please sign in to comment.