Skip to content

Commit 9abc5c3

Browse files
committed
improved coding style
1 parent e07f521 commit 9abc5c3

File tree

57 files changed

+494
-485
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+494
-485
lines changed

src/Application/Application.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,22 @@ class Application extends Nette\Object
3131
/** @var string */
3232
public $errorPresenter;
3333

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

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

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

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

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

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

5252
/** @var Request[] */

src/Application/PresenterFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ class PresenterFactory extends Nette\Object implements IPresenterFactory
3131

3232

3333
/**
34-
* @param callable function(string $class): IPresenter
34+
* @param callable function (string $class): IPresenter
3535
*/
3636
public function __construct($factory = NULL)
3737
{
38-
$this->factory = $factory ?: function($class) { return new $class; };
38+
$this->factory = $factory ?: function ($class) { return new $class; };
3939
}
4040

4141

src/Application/UI/Presenter.php

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ abstract class Presenter extends Control implements Application\IPresenter
4848
/** @var int */
4949
public $invalidLinkMode;
5050

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

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

226226
} catch (Application\AbortException $e) {
227227
// continue with shutting down
228-
if ($this->isAjax()) try {
229-
$hasPayload = (array) $this->payload; unset($hasPayload['state']);
230-
if ($this->response instanceof Responses\TextResponse && $this->isControlInvalid()) {
231-
$this->snippetMode = TRUE;
232-
$this->response->send($this->httpRequest, $this->httpResponse);
233-
$this->sendPayload();
234-
235-
} elseif (!$this->response && $hasPayload) { // back compatibility for use terminate() instead of sendPayload()
228+
if ($this->isAjax()) {
229+
try {
230+
$hasPayload = (array) $this->payload;
231+
unset($hasPayload['state']);
232+
if ($this->response instanceof Responses\TextResponse && $this->isControlInvalid()) {
233+
$this->snippetMode = TRUE;
234+
$this->response->send($this->httpRequest, $this->httpResponse);
235+
$this->sendPayload();
236+
} elseif (!$this->response && $hasPayload) { // back compatibility for use terminate() instead of sendPayload()
236237
$this->sendPayload();
238+
}
239+
} catch (Application\AbortException $e) {
237240
}
238-
} catch (Application\AbortException $e) { }
241+
}
239242

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

315318
try {
316319
$component = $this->signalReceiver === '' ? $this : $this->getComponent($this->signalReceiver, FALSE);
317-
} catch (Nette\InvalidArgumentException $e) {}
320+
} catch (Nette\InvalidArgumentException $e) {
321+
}
318322

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

603607
/**
604608
* Sends JSON data to the output.
605-
* @param mixed $data
609+
* @param mixed
606610
* @return void
607611
* @throws Nette\Application\AbortException
608612
*/
@@ -735,7 +739,8 @@ public function canonicalize()
735739
if (!$this->isAjax() && ($this->request->isMethod('get') || $this->request->isMethod('head'))) {
736740
try {
737741
$url = $this->createRequest($this, $this->action, $this->getGlobalState() + $this->request->getParameters(), 'redirectX');
738-
} catch (InvalidLinkException $e) {}
742+
} catch (InvalidLinkException $e) {
743+
}
739744
if (isset($url) && !$this->httpRequest->getUrl()->isEqual($url)) {
740745
$this->sendResponse(new Responses\RedirectResponse($url, Http\IResponse::S301_MOVED_PERMANENTLY));
741746
}
@@ -806,21 +811,21 @@ protected function createRequest($component, $destination, array $args, $mode)
806811
}
807812

808813
// 4) signal or empty
809-
if (!$component instanceof Presenter || substr($destination, -1) === '!') {
814+
if (!$component instanceof self || substr($destination, -1) === '!') {
810815
$signal = rtrim($destination, '!');
811816
$a = strrpos($signal, ':');
812817
if ($a !== FALSE) {
813818
$component = $component->getComponent(strtr(substr($signal, 0, $a), ':', '-'));
814819
$signal = (string) substr($signal, $a + 1);
815820
}
816821
if ($signal == NULL) { // intentionally ==
817-
throw new InvalidLinkException("Signal must be non-empty string.");
822+
throw new InvalidLinkException('Signal must be non-empty string.');
818823
}
819824
$destination = 'this';
820825
}
821826

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

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

13201325
$this->context = $context;
@@ -1368,7 +1373,7 @@ public function getSession($namespace = NULL)
13681373
{
13691374
if (!$this->session) {
13701375
throw new Nette\InvalidStateException('Service Session has not been set.');
1371-
}
1376+
}
13721377
return $namespace === NULL ? $this->session : $this->session->getSection($namespace);
13731378
}
13741379

src/Application/UI/PresenterComponentReflection.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,13 @@ public function hasCallableMethod($method)
101101
{
102102
$class = $this->getName();
103103
$cache = & self::$mcCache[strtolower($class . ':' . $method)];
104-
if ($cache === NULL) try {
105-
$cache = FALSE;
106-
$rm = new \ReflectionMethod($class, $method);
107-
$cache = $this->isInstantiable() && $rm->isPublic() && !$rm->isAbstract() && !$rm->isStatic();
108-
} catch (\ReflectionException $e) {
104+
if ($cache === NULL) {
105+
try {
106+
$cache = FALSE;
107+
$rm = new \ReflectionMethod($class, $method);
108+
$cache = $this->isInstantiable() && $rm->isPublic() && !$rm->isAbstract() && !$rm->isStatic();
109+
} catch (\ReflectionException $e) {
110+
}
109111
}
110112
return $cache;
111113
}
@@ -123,7 +125,7 @@ public static function combineArgs(\ReflectionFunctionAbstract $method, $args)
123125
if (isset($args[$name])) { // NULLs are ignored
124126
$res[$i++] = $args[$name];
125127
$type = $param->isArray() ? 'array' : ($param->isDefaultValueAvailable() ? gettype($param->getDefaultValue()) : 'NULL');
126-
if (!self::convertType($res[$i-1], $type)) {
128+
if (!self::convertType($res[$i - 1], $type)) {
127129
$mName = $method instanceof \ReflectionMethod ? $method->getDeclaringClass()->getName() . '::' . $method->getName() : $method->getName();
128130
throw new BadRequestException("Invalid value for parameter '$name' in method $mName(), expected " . ($type === 'NULL' ? 'scalar' : $type) . ".");
129131
}

src/Bridges/ApplicationDI/ApplicationExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private function findPresenters()
140140
$classFile = dirname($rc->getFileName()) . '/autoload_classmap.php';
141141
if (is_file($classFile)) {
142142
$this->getContainerBuilder()->addDependency($classFile);
143-
$classes = array_merge($classes, array_keys(call_user_func(function($path) {
143+
$classes = array_merge($classes, array_keys(call_user_func(function ($path) {
144144
return require $path;
145145
}, $classFile)));
146146
}

src/Bridges/ApplicationDI/LatteExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function loadConfiguration()
4747
$config = $this->validateConfig($this->defaults);
4848
$container = $this->getContainerBuilder();
4949

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

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

8989
}

src/Bridges/ApplicationDI/RoutingExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function beforeCompile()
5858

5959
if ($this->debugMode && $this->config['debugger'] && $application = $container->getByType('Nette\Application\Application')) {
6060
$container->getDefinition($application)->addSetup('@Tracy\Bar::addPanel', [
61-
new Nette\DI\Statement('Nette\Bridges\ApplicationTracy\RoutingPanel')
61+
new Nette\DI\Statement('Nette\Bridges\ApplicationTracy\RoutingPanel'),
6262
]);
6363
}
6464
}

src/Bridges/ApplicationLatte/Template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function registerHelperLoader($loader)
105105
{
106106
trigger_error(__METHOD__ . '() is deprecated, use dynamic getLatte()->addFilter().', E_USER_DEPRECATED);
107107
$latte = $this->latte;
108-
$this->latte->addFilter(NULL, function($name) use ($loader, $latte) {
108+
$this->latte->addFilter(NULL, function ($name) use ($loader, $latte) {
109109
if ($callback = call_user_func($loader, $name)) {
110110
$latte->addFilter($name, $callback);
111111
}

src/Bridges/ApplicationLatte/TemplateFactory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function createTemplate(UI\Control $control = NULL)
6666
$latte->onCompile = iterator_to_array($latte->onCompile);
6767
}
6868

69-
array_unshift($latte->onCompile, function($latte) use ($control, $template) {
69+
array_unshift($latte->onCompile, function ($latte) use ($control, $template) {
7070
$latte->getParser()->shortNoEscape = TRUE;
7171
$latte->getCompiler()->addMacro('cache', new Nette\Bridges\CacheLatte\CacheMacro($latte->getCompiler()));
7272
UIMacros::install($latte->getCompiler());
@@ -82,11 +82,11 @@ public function createTemplate(UI\Control $control = NULL)
8282
foreach (['normalize', 'toAscii', 'webalize', 'padLeft', 'padRight', 'reverse'] as $name) {
8383
$latte->addFilter($name, 'Nette\Utils\Strings::' . $name);
8484
}
85-
$latte->addFilter('null', function() {});
86-
$latte->addFilter('length', function($var) {
85+
$latte->addFilter('null', function () {});
86+
$latte->addFilter('length', function ($var) {
8787
return is_string($var) ? Nette\Utils\Strings::length($var) : count($var);
8888
});
89-
$latte->addFilter('modifyDate', function($time, $delta, $unit = NULL) {
89+
$latte->addFilter('modifyDate', function ($time, $delta, $unit = NULL) {
9090
return $time == NULL ? NULL : Nette\Utils\DateTime::from($time)->modify($delta . $unit); // intentionally ==
9191
});
9292

src/Bridges/ApplicationLatte/UIMacros.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static function install(Latte\Compiler $compiler)
3232
$me = new static($compiler);
3333
$me->addMacro('control', [$me, 'macroControl']);
3434

35-
$me->addMacro('href', NULL, NULL, function(MacroNode $node, PhpWriter $writer) use ($me) {
35+
$me->addMacro('href', NULL, NULL, function (MacroNode $node, PhpWriter $writer) use ($me) {
3636
return ' ?> href="<?php ' . $me->macroLink($node, $writer) . ' ?>"<?php ';
3737
});
3838
$me->addMacro('plink', [$me, 'macroLink']);

src/Bridges/ApplicationTracy/RoutingPanel.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ class RoutingPanel extends Nette\Object implements Tracy\IBarPanel
4242

4343
public static function initializePanel(Nette\Application\Application $application)
4444
{
45-
Tracy\Debugger::getBlueScreen()->addPanel(function($e) use ($application) {
45+
Tracy\Debugger::getBlueScreen()->addPanel(function ($e) use ($application) {
4646
return $e ? NULL : [
4747
'tab' => 'Nette Application',
4848
'panel' => '<h3>Requests</h3>' . Dumper::toHtml($application->getRequests(), [Dumper::LIVE => TRUE])
49-
. '<h3>Presenter</h3>' . Dumper::toHtml($application->getPresenter(), [Dumper::LIVE => TRUE])
49+
. '<h3>Presenter</h3>' . Dumper::toHtml($application->getPresenter(), [Dumper::LIVE => TRUE]),
5050
];
5151
});
5252
}
@@ -122,7 +122,7 @@ private function analyse($router, $module = '')
122122
'defaults' => $router instanceof Routers\Route || $router instanceof Routers\SimpleRouter ? $router->getDefaults() : [],
123123
'mask' => $router instanceof Routers\Route ? $router->getMask() : NULL,
124124
'request' => $request,
125-
'module' => rtrim($module, ':')
125+
'module' => rtrim($module, ':'),
126126
];
127127
}
128128

tests/Application.DI/ApplicationExtension.basic.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use Nette\DI,
1212
require __DIR__ . '/../bootstrap.php';
1313

1414

15-
test(function() {
15+
test(function () {
1616
$compiler = new DI\Compiler;
1717
$compiler->addExtension('application', new ApplicationExtension(FALSE));
1818

@@ -27,7 +27,7 @@ test(function() {
2727
eval($code);
2828

2929
$container = new Container1;
30-
Assert::type( 'Nette\Application\Application', $container->getService('application') );
31-
Assert::type( 'Nette\Application\PresenterFactory', $container->getService('nette.presenterFactory') );
32-
Assert::type( 'Nette\Application\LinkGenerator', $container->getService('application.linkGenerator') );
30+
Assert::type('Nette\Application\Application', $container->getService('application'));
31+
Assert::type('Nette\Application\PresenterFactory', $container->getService('nette.presenterFactory'));
32+
Assert::type('Nette\Application\LinkGenerator', $container->getService('application.linkGenerator'));
3333
});

tests/Application.DI/ApplicationExtension.invalidLink.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function createCompiler($config)
2626
}
2727

2828

29-
test(function() {
29+
test(function () {
3030
$compiler = createCompiler('
3131
application:
3232
debugger: no
@@ -47,7 +47,7 @@ test(function() {
4747
});
4848

4949

50-
test(function() {
50+
test(function () {
5151
$compiler = createCompiler('
5252
application:
5353
debugger: no
@@ -68,7 +68,7 @@ test(function() {
6868
});
6969

7070

71-
test(function() {
71+
test(function () {
7272
$compiler = createCompiler('
7373
application:
7474
debugger: no
@@ -89,7 +89,7 @@ test(function() {
8989
});
9090

9191

92-
test(function() {
92+
test(function () {
9393
$compiler = createCompiler('
9494
application:
9595
debugger: no

tests/Application.DI/ApplicationExtension.scan.phpt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require __DIR__ . '/../bootstrap.php';
1313
require __DIR__ . '/files/MyPresenter.php';
1414

1515

16-
test(function() {
16+
test(function () {
1717
$compiler = new DI\Compiler;
1818
$compiler->addExtension('application', new ApplicationExtension);
1919

@@ -28,13 +28,13 @@ test(function() {
2828

2929
$container = new Container1;
3030
$tags = $container->findByTag('nette.presenter');
31-
Assert::count( 1, array_keys($tags, 'NetteModule\ErrorPresenter') );
32-
Assert::count( 1, array_keys($tags, 'NetteModule\MicroPresenter') );
33-
Assert::count( 0, array_keys($tags, 'Nette\Application\UI\Presenter') );
31+
Assert::count(1, array_keys($tags, 'NetteModule\ErrorPresenter'));
32+
Assert::count(1, array_keys($tags, 'NetteModule\MicroPresenter'));
33+
Assert::count(0, array_keys($tags, 'Nette\Application\UI\Presenter'));
3434
});
3535

3636

37-
test(function() {
37+
test(function () {
3838
$compiler = new DI\Compiler;
3939
$compiler->addExtension('application', new ApplicationExtension);
4040

@@ -52,13 +52,13 @@ test(function() {
5252

5353
$container = new Container2;
5454
$tags = $container->findByTag('nette.presenter');
55-
Assert::count( 1, array_keys($tags, 'BasePresenter') );
56-
Assert::count( 1, array_keys($tags, 'Presenter1') );
57-
Assert::count( 1, array_keys($tags, 'Presenter2') );
55+
Assert::count(1, array_keys($tags, 'BasePresenter'));
56+
Assert::count(1, array_keys($tags, 'Presenter1'));
57+
Assert::count(1, array_keys($tags, 'Presenter2'));
5858
});
5959

6060

61-
test(function() {
61+
test(function () {
6262
$compiler = new DI\Compiler;
6363
$compiler->addExtension('application', new ApplicationExtension(FALSE, [__DIR__ . '/files']));
6464

@@ -82,10 +82,10 @@ test(function() {
8282

8383
$container = new Container3;
8484
$tags = $container->findByTag('nette.presenter');
85-
Assert::count( 1, array_keys($tags, 'BasePresenter') );
86-
Assert::count( 1, array_keys($tags, 'Presenter1') );
87-
Assert::count( 1, array_keys($tags, 'Presenter2') );
85+
Assert::count(1, array_keys($tags, 'BasePresenter'));
86+
Assert::count(1, array_keys($tags, 'Presenter1'));
87+
Assert::count(1, array_keys($tags, 'Presenter2'));
8888

8989
$tmp = array_keys($tags, 'Presenter1');
90-
Assert::same( 'test', $container->getService($tmp[0])->getView() );
90+
Assert::same('test', $container->getService($tmp[0])->getView());
9191
});

0 commit comments

Comments
 (0)