Skip to content

Commit c39fd7b

Browse files
committed
utilization of operator ??
1 parent 4002535 commit c39fd7b

File tree

10 files changed

+23
-57
lines changed

10 files changed

+23
-57
lines changed

src/Application/Request.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function getParameters()
122122
*/
123123
public function getParameter($key)
124124
{
125-
return isset($this->params[$key]) ? $this->params[$key] : NULL;
125+
return $this->params[$key] ?? NULL;
126126
}
127127

128128

@@ -145,15 +145,9 @@ public function setPost(array $params)
145145
*/
146146
public function getPost($key = NULL)
147147
{
148-
if (func_num_args() === 0) {
149-
return $this->post;
150-
151-
} elseif (isset($this->post[$key])) {
152-
return $this->post[$key];
153-
154-
} else {
155-
return NULL;
156-
}
148+
return func_num_args() === 0
149+
? $this->post
150+
: ($this->post[$key] ?? NULL);
157151
}
158152

159153

src/Application/Routers/Route.php

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function match(Nette\Http\IRequest $httpRequest)
156156
'/%basePath%/' => preg_quote($url->getBasePath(), '#'),
157157
'%tld%' => preg_quote($parts[0], '#'),
158158
'%domain%' => preg_quote(isset($parts[1]) ? "$parts[1].$parts[0]" : $parts[0], '#'),
159-
'%sld%' => preg_quote(isset($parts[1]) ? $parts[1] : '', '#'),
159+
'%sld%' => preg_quote($parts[1] ?? '', '#'),
160160
'%host%' => preg_quote($host, '#'),
161161
]);
162162

@@ -391,7 +391,7 @@ public function constructUrl(Application\Request $appRequest, Nette\Http\Url $re
391391
'/%basePath%/' => $refUrl->getBasePath(),
392392
'%tld%' => $parts[0],
393393
'%domain%' => isset($parts[1]) ? "$parts[1].$parts[0]" : $parts[0],
394-
'%sld%' => isset($parts[1]) ? $parts[1] : '',
394+
'%sld%' => $parts[1] ?? '',
395395
'%host%' => $host,
396396
]);
397397
$url = $scheme . ':' . $url;
@@ -478,15 +478,7 @@ private function setMask($mask, array $metadata)
478478
$matches = Strings::matchAll($parts[$i - 1], '/(?:([a-zA-Z0-9_.-]+)=)?<([^> ]+) *([^>]*)>/');
479479

480480
foreach ($matches as list(, $param, $name, $pattern)) { // $pattern is not used
481-
if (isset(static::$styles['?' . $name])) {
482-
$meta = static::$styles['?' . $name];
483-
} else {
484-
$meta = static::$styles['?#'];
485-
}
486-
487-
if (isset($metadata[$name])) {
488-
$meta = $metadata[$name] + $meta;
489-
}
481+
$meta = ($metadata[$name] ?? []) + (static::$styles['?' . $name] ?? static::$styles['?#']);
490482

491483
if (array_key_exists(self::VALUE, $meta)) {
492484
$meta['fixity'] = self::OPTIONAL;
@@ -546,15 +538,7 @@ private function setMask($mask, array $metadata)
546538
}
547539

548540
// pattern, condition & metadata
549-
if (isset(static::$styles[$name])) {
550-
$meta = static::$styles[$name];
551-
} else {
552-
$meta = static::$styles['#'];
553-
}
554-
555-
if (isset($metadata[$name])) {
556-
$meta = $metadata[$name] + $meta;
557-
}
541+
$meta = ($metadata[$name] ?? []) + (static::$styles[$name] ?? static::$styles['#']);
558542

559543
if ($pattern == '' && isset($meta[self::PATTERN])) {
560544
$pattern = $meta[self::PATTERN];
@@ -667,14 +651,14 @@ public function getTargetPresenters()
667651
$module = '';
668652

669653
if (isset($m[self::MODULE_KEY])) {
670-
if (isset($m[self::MODULE_KEY]['fixity']) && $m[self::MODULE_KEY]['fixity'] === self::CONSTANT) {
654+
if (($m[self::MODULE_KEY]['fixity'] ?? NULL) === self::CONSTANT) {
671655
$module = $m[self::MODULE_KEY][self::VALUE] . ':';
672656
} else {
673657
return NULL;
674658
}
675659
}
676660

677-
if (isset($m[self::PRESENTER_KEY]['fixity']) && $m[self::PRESENTER_KEY]['fixity'] === self::CONSTANT) {
661+
if (($m[self::PRESENTER_KEY]['fixity'] ?? NULL) === self::CONSTANT) {
678662
return [$module . $m[self::PRESENTER_KEY][self::VALUE]];
679663
}
680664
return NULL;

src/Application/UI/Component.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,7 @@ public function saveState(array &$params, $reflection = NULL)
200200
*/
201201
public function getParameter($name, $default = NULL)
202202
{
203-
if (isset($this->params[$name])) {
204-
return $this->params[$name];
205-
206-
} else {
207-
return $default;
208-
}
203+
return $this->params[$name] ?? $default;
209204
}
210205

211206

src/Application/UI/Control.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,8 @@ public function isControlInvalid($snippet = NULL)
149149
return FALSE;
150150
}
151151

152-
} elseif (isset($this->invalidSnippets[$snippet])) {
153-
return $this->invalidSnippets[$snippet];
154152
} else {
155-
return isset($this->invalidSnippets["\0"]);
153+
return $this->invalidSnippets[$snippet] ?? isset($this->invalidSnippets["\0"]);
156154
}
157155
}
158156

src/Application/UI/Link.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function setParameter($key, $value)
7171
*/
7272
public function getParameter($key)
7373
{
74-
return isset($this->params[$key]) ? $this->params[$key] : NULL;
74+
return $this->params[$key] ?? NULL;
7575
}
7676

7777

src/Application/UI/Presenter.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ protected function getGlobalState($forClass = NULL)
11481148
foreach ($iterator as $name => $component) {
11491149
if ($iterator->getDepth() === 0) {
11501150
// counts with Nette\Application\RecursiveIteratorIterator::SELF_FIRST
1151-
$since = isset($components[$name]['since']) ? $components[$name]['since'] : FALSE; // FALSE = nonpersistent
1151+
$since = $components[$name]['since'] ?? FALSE; // FALSE = nonpersistent
11521152
}
11531153
$prefix = $component->getUniqueId() . self::NAME_SEPARATOR;
11541154
$params = [];
@@ -1169,7 +1169,7 @@ protected function getGlobalState($forClass = NULL)
11691169
if (!isset($sinces[$key])) {
11701170
$x = strpos($key, self::NAME_SEPARATOR);
11711171
$x = $x === FALSE ? $key : substr($key, 0, $x);
1172-
$sinces[$key] = isset($sinces[$x]) ? $sinces[$x] : FALSE;
1172+
$sinces[$key] = $sinces[$x] ?? FALSE;
11731173
}
11741174
if ($since !== $sinces[$key]) {
11751175
$since = $sinces[$key];
@@ -1228,7 +1228,7 @@ private function initGlobalParameters()
12281228
}
12291229

12301230
// init & validate $this->action & $this->view
1231-
$this->changeAction(isset($selfParams[self::ACTION_KEY]) ? $selfParams[self::ACTION_KEY] : self::DEFAULT_ACTION);
1231+
$this->changeAction($selfParams[self::ACTION_KEY] ?? self::DEFAULT_ACTION);
12321232

12331233
// init $this->signalReceiver and key 'signal' in appropriate params array
12341234
$this->signalReceiver = $this->getUniqueId();
@@ -1262,14 +1262,9 @@ private function initGlobalParameters()
12621262
*/
12631263
public function popGlobalParameters($id)
12641264
{
1265-
if (isset($this->globalParams[$id])) {
1266-
$res = $this->globalParams[$id];
1267-
unset($this->globalParams[$id]);
1268-
return $res;
1269-
1270-
} else {
1271-
return [];
1272-
}
1265+
$res = $this->globalParams[$id] ?? [];
1266+
unset($this->globalParams[$id]);
1267+
return $res;
12731268
}
12741269

12751270

src/Bridges/ApplicationDI/LatteExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function addMacro($macro)
8585
$builder = $this->getContainerBuilder();
8686
$definition = $builder->getDefinition($this->prefix('latteFactory'));
8787

88-
if (isset($macro[0]) && $macro[0] === '@') {
88+
if (($macro[0] ?? NULL) === '@') {
8989
if (strpos($macro, '::') === FALSE) {
9090
$method = 'install';
9191
} else {

src/Bridges/ApplicationLatte/UIMacros.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function macroControl(MacroNode $node, PhpWriter $writer)
8181
throw new CompileException('Missing control name in {control}');
8282
}
8383
$name = $writer->formatWord($words[0]);
84-
$method = isset($words[1]) ? ucfirst($words[1]) : '';
84+
$method = ucfirst($words[1] ?? '');
8585
$method = Strings::match($method, '#^\w*\z#') ? "render$method" : "{\"render$method\"}";
8686

8787
$tokens = $node->tokenizer;

src/Bridges/ApplicationLatte/UIRuntime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static function initialize(Latte\Runtime\Template $template, &$parentName
2929
$providers = $template->global;
3030
$blocks = array_filter(array_keys($blocks), function ($s) { return $s[0] !== '_'; });
3131
if ($parentName === NULL && $blocks && !$template->getReferringTemplate()
32-
&& isset($providers->uiControl) && $providers->uiControl instanceof Nette\Application\UI\Presenter
32+
&& ($providers->uiControl ?? NULL) instanceof Nette\Application\UI\Presenter
3333
) {
3434
$parentName = $providers->uiControl->findLayoutTemplateFile();
3535
}

tests/Routers/Route.filter.url.object.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $route = new Route('<parameter>', [
2525
'presenter' => 'presenter',
2626
'parameter' => [
2727
Route::FILTER_IN => function ($s) use ($identityMap) {
28-
return isset($identityMap[$s]) ? $identityMap[$s] : NULL;
28+
return $identityMap[$s] ?? NULL;
2929
},
3030
Route::FILTER_OUT => function ($obj) {
3131
return $obj instanceof RouterObject ? $obj->getId() : NULL;

0 commit comments

Comments
 (0)