Skip to content

Commit

Permalink
improved coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jun 21, 2015
1 parent e07f521 commit d36f845
Show file tree
Hide file tree
Showing 114 changed files with 758 additions and 751 deletions.
12 changes: 6 additions & 6 deletions src/Application/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@ class Application extends Nette\Object
/** @var string */
public $errorPresenter;

/** @var callable[] function(Application $sender); Occurs before the application loads presenter */
/** @var callable[] function (Application $sender); Occurs before the application loads presenter */
public $onStartup;

/** @var callable[] function(Application $sender, \Exception $e = NULL); Occurs before the application shuts down */
/** @var callable[] function (Application $sender, \Exception $e = NULL); Occurs before the application shuts down */
public $onShutdown;

/** @var callable[] function(Application $sender, Request $request); Occurs when a new request is received */
/** @var callable[] function (Application $sender, Request $request); Occurs when a new request is received */
public $onRequest;

/** @var callable[] function(Application $sender, Presenter $presenter); Occurs when a presenter is created */
/** @var callable[] function (Application $sender, Presenter $presenter); Occurs when a presenter is created */
public $onPresenter;

/** @var callable[] function(Application $sender, IResponse $response); Occurs when a new response is ready for dispatch */
/** @var callable[] function (Application $sender, IResponse $response); Occurs when a new response is ready for dispatch */
public $onResponse;

/** @var callable[] function(Application $sender, \Exception $e); Occurs when an unhandled exception occurs in the application */
/** @var callable[] function (Application $sender, \Exception $e); Occurs when an unhandled exception occurs in the application */
public $onError;

/** @var Request[] */
Expand Down
6 changes: 3 additions & 3 deletions src/Application/ErrorPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

namespace NetteModule;

use Nette,
Nette\Application,
Tracy\ILogger;
use Nette;
use Nette\Application;
use Tracy\ILogger;


/**
Expand Down
10 changes: 5 additions & 5 deletions src/Application/MicroPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

namespace NetteModule;

use Nette,
Nette\Application,
Nette\Application\Responses,
Nette\Http,
Latte;
use Nette;
use Nette\Application;
use Nette\Application\Responses;
use Nette\Http;
use Latte;


/**
Expand Down
4 changes: 2 additions & 2 deletions src/Application/PresenterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class PresenterFactory extends Nette\Object implements IPresenterFactory


/**
* @param callable function(string $class): IPresenter
* @param callable function (string $class): IPresenter
*/
public function __construct($factory = NULL)
{
$this->factory = $factory ?: function($class) { return new $class; };
$this->factory = $factory ?: function ($class) { return new $class; };
}


Expand Down
4 changes: 2 additions & 2 deletions src/Application/Responses/RedirectResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace Nette\Application\Responses;

use Nette,
Nette\Http;
use Nette;
use Nette\Http;


/**
Expand Down
4 changes: 2 additions & 2 deletions src/Application/Routers/CliRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace Nette\Application\Routers;

use Nette,
Nette\Application;
use Nette;
use Nette\Application;


/**
Expand Down
6 changes: 3 additions & 3 deletions src/Application/Routers/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

namespace Nette\Application\Routers;

use Nette,
Nette\Application,
Nette\Utils\Strings;
use Nette;
use Nette\Application;
use Nette\Utils\Strings;


/**
Expand Down
4 changes: 2 additions & 2 deletions src/Application/Routers/SimpleRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace Nette\Application\Routers;

use Nette,
Nette\Application;
use Nette;
use Nette\Application;


/**
Expand Down
49 changes: 27 additions & 22 deletions src/Application/UI/Presenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

namespace Nette\Application\UI;

use Nette,
Nette\Application,
Nette\Application\Responses,
Nette\Http;
use Nette;
use Nette\Application;
use Nette\Application\Responses;
use Nette\Http;


/**
Expand Down Expand Up @@ -48,7 +48,7 @@ abstract class Presenter extends Control implements Application\IPresenter
/** @var int */
public $invalidLinkMode;

/** @var callable[] function(Presenter $sender, IResponse $response = NULL); Occurs when the presenter is shutting down */
/** @var callable[] function (Presenter $sender, IResponse $response = NULL); Occurs when the presenter is shutting down */
public $onShutdown;

/** @var Nette\Application\Request */
Expand Down Expand Up @@ -225,17 +225,20 @@ public function run(Application\Request $request)

} catch (Application\AbortException $e) {
// continue with shutting down
if ($this->isAjax()) try {
$hasPayload = (array) $this->payload; unset($hasPayload['state']);
if ($this->response instanceof Responses\TextResponse && $this->isControlInvalid()) {
$this->snippetMode = TRUE;
$this->response->send($this->httpRequest, $this->httpResponse);
$this->sendPayload();

} elseif (!$this->response && $hasPayload) { // back compatibility for use terminate() instead of sendPayload()
if ($this->isAjax()) {
try {
$hasPayload = (array) $this->payload;
unset($hasPayload['state']);
if ($this->response instanceof Responses\TextResponse && $this->isControlInvalid()) {
$this->snippetMode = TRUE;
$this->response->send($this->httpRequest, $this->httpResponse);
$this->sendPayload();
} elseif (!$this->response && $hasPayload) { // back compatibility for use terminate() instead of sendPayload()
$this->sendPayload();
}
} catch (Application\AbortException $e) {
}
} catch (Application\AbortException $e) { }
}

if ($this->hasFlashSession()) {
$this->getFlashSession()->setExpiration($this->response instanceof Responses\RedirectResponse ? '+ 30 seconds' : '+ 3 seconds');
Expand Down Expand Up @@ -314,7 +317,8 @@ public function processSignal()

try {
$component = $this->signalReceiver === '' ? $this : $this->getComponent($this->signalReceiver, FALSE);
} catch (Nette\InvalidArgumentException $e) {}
} catch (Nette\InvalidArgumentException $e) {
}

if (isset($e) || $component === NULL) {
throw new BadSignalException("The signal receiver component '$this->signalReceiver' is not found.", NULL, isset($e) ? $e : NULL);
Expand Down Expand Up @@ -602,7 +606,7 @@ public function sendPayload()

/**
* Sends JSON data to the output.
* @param mixed $data
* @param mixed
* @return void
* @throws Nette\Application\AbortException
*/
Expand Down Expand Up @@ -735,7 +739,8 @@ public function canonicalize()
if (!$this->isAjax() && ($this->request->isMethod('get') || $this->request->isMethod('head'))) {
try {
$url = $this->createRequest($this, $this->action, $this->getGlobalState() + $this->request->getParameters(), 'redirectX');
} catch (InvalidLinkException $e) {}
} catch (InvalidLinkException $e) {
}
if (isset($url) && !$this->httpRequest->getUrl()->isEqual($url)) {
$this->sendResponse(new Responses\RedirectResponse($url, Http\IResponse::S301_MOVED_PERMANENTLY));
}
Expand Down Expand Up @@ -806,21 +811,21 @@ protected function createRequest($component, $destination, array $args, $mode)
}

// 4) signal or empty
if (!$component instanceof Presenter || substr($destination, -1) === '!') {
if (!$component instanceof self || substr($destination, -1) === '!') {
$signal = rtrim($destination, '!');
$a = strrpos($signal, ':');
if ($a !== FALSE) {
$component = $component->getComponent(strtr(substr($signal, 0, $a), ':', '-'));
$signal = (string) substr($signal, $a + 1);
}
if ($signal == NULL) { // intentionally ==
throw new InvalidLinkException("Signal must be non-empty string.");
throw new InvalidLinkException('Signal must be non-empty string.');
}
$destination = 'this';
}

if ($destination == NULL) { // intentionally ==
throw new InvalidLinkException("Destination must be non-empty string.");
throw new InvalidLinkException('Destination must be non-empty string.');
}

// 5) presenter: action
Expand Down Expand Up @@ -1314,7 +1319,7 @@ public function injectPrimary(Nette\DI\Container $context = NULL, Application\IP
Http\IRequest $httpRequest, Http\IResponse $httpResponse, Http\Session $session = NULL, Nette\Security\User $user = NULL, ITemplateFactory $templateFactory = NULL)
{
if ($this->presenterFactory !== NULL) {
throw new Nette\InvalidStateException("Method " . __METHOD__ . " is intended for initialization and should not be called more than once.");
throw new Nette\InvalidStateException('Method ' . __METHOD__ . ' is intended for initialization and should not be called more than once.');
}

$this->context = $context;
Expand Down Expand Up @@ -1368,7 +1373,7 @@ public function getSession($namespace = NULL)
{
if (!$this->session) {
throw new Nette\InvalidStateException('Service Session has not been set.');
}
}
return $namespace === NULL ? $this->session : $this->session->getSection($namespace);
}

Expand Down
18 changes: 10 additions & 8 deletions src/Application/UI/PresenterComponentReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace Nette\Application\UI;

use Nette,
Nette\Application\BadRequestException;
use Nette;
use Nette\Application\BadRequestException;


/**
Expand Down Expand Up @@ -101,11 +101,13 @@ public function hasCallableMethod($method)
{
$class = $this->getName();
$cache = & self::$mcCache[strtolower($class . ':' . $method)];
if ($cache === NULL) try {
$cache = FALSE;
$rm = new \ReflectionMethod($class, $method);
$cache = $this->isInstantiable() && $rm->isPublic() && !$rm->isAbstract() && !$rm->isStatic();
} catch (\ReflectionException $e) {
if ($cache === NULL) {
try {
$cache = FALSE;
$rm = new \ReflectionMethod($class, $method);
$cache = $this->isInstantiable() && $rm->isPublic() && !$rm->isAbstract() && !$rm->isStatic();
} catch (\ReflectionException $e) {
}
}
return $cache;
}
Expand All @@ -123,7 +125,7 @@ public static function combineArgs(\ReflectionFunctionAbstract $method, $args)
if (isset($args[$name])) { // NULLs are ignored
$res[$i++] = $args[$name];
$type = $param->isArray() ? 'array' : ($param->isDefaultValueAvailable() ? gettype($param->getDefaultValue()) : 'NULL');
if (!self::convertType($res[$i-1], $type)) {
if (!self::convertType($res[$i - 1], $type)) {
$mName = $method instanceof \ReflectionMethod ? $method->getDeclaringClass()->getName() . '::' . $method->getName() : $method->getName();
throw new BadRequestException("Invalid value for parameter '$name' in method $mName(), expected " . ($type === 'NULL' ? 'scalar' : $type) . ".");
}
Expand Down
6 changes: 3 additions & 3 deletions src/Bridges/ApplicationDI/ApplicationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace Nette\Bridges\ApplicationDI;

use Nette,
Nette\Application\UI;
use Nette;
use Nette\Application\UI;


/**
Expand Down Expand Up @@ -140,7 +140,7 @@ private function findPresenters()
$classFile = dirname($rc->getFileName()) . '/autoload_classmap.php';
if (is_file($classFile)) {
$this->getContainerBuilder()->addDependency($classFile);
$classes = array_merge($classes, array_keys(call_user_func(function($path) {
$classes = array_merge($classes, array_keys(call_user_func(function ($path) {
return require $path;
}, $classFile)));
}
Expand Down
8 changes: 4 additions & 4 deletions src/Bridges/ApplicationDI/LatteExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace Nette\Bridges\ApplicationDI;

use Nette,
Latte;
use Nette;
use Latte;


/**
Expand Down Expand Up @@ -47,7 +47,7 @@ public function loadConfiguration()
$config = $this->validateConfig($this->defaults);
$container = $this->getContainerBuilder();

$latteFactory = $container->addDefinition($this->prefix('latteFactory'))
$container->addDefinition($this->prefix('latteFactory'))
->setClass('Latte\Engine')
->addSetup('setTempDirectory', [$this->tempDir])
->addSetup('setAutoRefresh', [$this->debugMode])
Expand Down Expand Up @@ -83,7 +83,7 @@ public function addMacro($macro)

$container = $this->getContainerBuilder();
$container->getDefinition($this->prefix('latteFactory'))
->addSetup('?->onCompile[] = function($engine) { ' . $macro . '($engine->getCompiler()); }', ['@self']);
->addSetup('?->onCompile[] = function ($engine) { ' . $macro . '($engine->getCompiler()); }', ['@self']);
}

}
2 changes: 1 addition & 1 deletion src/Bridges/ApplicationDI/RoutingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function beforeCompile()

if ($this->debugMode && $this->config['debugger'] && $application = $container->getByType('Nette\Application\Application')) {
$container->getDefinition($application)->addSetup('@Tracy\Bar::addPanel', [
new Nette\DI\Statement('Nette\Bridges\ApplicationTracy\RoutingPanel')
new Nette\DI\Statement('Nette\Bridges\ApplicationTracy\RoutingPanel'),
]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Bridges/ApplicationLatte/ILatteFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace Nette\Bridges\ApplicationLatte;

use Nette,
Latte;
use Nette;
use Latte;


interface ILatteFactory
Expand Down
4 changes: 2 additions & 2 deletions src/Bridges/ApplicationLatte/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace Nette\Bridges\ApplicationLatte;

use Nette,
Latte;
use Nette;
use Latte;


/**
Expand Down
6 changes: 3 additions & 3 deletions src/Bridges/ApplicationLatte/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace Nette\Bridges\ApplicationLatte;

use Nette,
Latte;
use Nette;
use Latte;


/**
Expand Down Expand Up @@ -105,7 +105,7 @@ public function registerHelperLoader($loader)
{
trigger_error(__METHOD__ . '() is deprecated, use dynamic getLatte()->addFilter().', E_USER_DEPRECATED);
$latte = $this->latte;
$this->latte->addFilter(NULL, function($name) use ($loader, $latte) {
$this->latte->addFilter(NULL, function ($name) use ($loader, $latte) {
if ($callback = call_user_func($loader, $name)) {
$latte->addFilter($name, $callback);
}
Expand Down

0 comments on commit d36f845

Please sign in to comment.