Skip to content

Commit 90b72f6

Browse files
committed
PHP 7.1: short list syntax, ?? operator, nullable types
1 parent 09780fd commit 90b72f6

File tree

18 files changed

+45
-45
lines changed

18 files changed

+45
-45
lines changed

HTML/QuickForm2.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function __construct(
7575
);
7676
parent::setId(empty($id) ? null : $id);
7777
if (!isset($this->attributes['action'])) {
78-
$this->attributes['action'] = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : '';
78+
$this->attributes['action'] = $_SERVER['PHP_SELF'] ?? '';
7979
}
8080
if ($trackSubmit && isset($_REQUEST['_qf__' . $id]) ||
8181
!$trackSubmit && ('get' == $method && !empty($_GET) ||
@@ -98,7 +98,7 @@ protected function onAttributeChange($name, $value = null)
9898
);
9999
}
100100

101-
protected function setContainer(HTML_QuickForm2_Container $container = null)
101+
protected function setContainer(?HTML_QuickForm2_Container $container = null)
102102
{
103103
throw new HTML_QuickForm2_Exception('Form cannot be added to container');
104104
}

HTML/QuickForm2/Container.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public static function arrayMerge($a, $b)
201201
if (!is_array($v) || isset($a[$k]) && !is_array($a[$k])) {
202202
$a[$k] = $v;
203203
} else {
204-
$a[$k] = self::arrayMerge(isset($a[$k])? $a[$k]: [], $v);
204+
$a[$k] = self::arrayMerge($a[$k] ?? [], $v);
205205
}
206206
}
207207
return $a;
@@ -342,12 +342,12 @@ public function getElementsByName($name)
342342
*
343343
* If the reference object is not given, the element will be appended.
344344
*
345-
* @param HTML_QuickForm2_Node $element Element to insert
346-
* @param HTML_QuickForm2_Node $reference Reference to insert before
345+
* @param HTML_QuickForm2_Node $element Element to insert
346+
* @param ?HTML_QuickForm2_Node $reference Reference to insert before
347347
*
348348
* @return HTML_QuickForm2_Node Inserted element
349349
*/
350-
public function insertBefore(HTML_QuickForm2_Node $element, HTML_QuickForm2_Node $reference = null)
350+
public function insertBefore(HTML_QuickForm2_Node $element, ?HTML_QuickForm2_Node $reference = null)
351351
{
352352
if (null === $reference) {
353353
return $this->appendChild($element);
@@ -465,9 +465,9 @@ public function __call($m, $a)
465465
if (preg_match('/^(add)([a-zA-Z0-9_]+)$/', $m, $match)) {
466466
if ($match[1] == 'add') {
467467
$type = strtolower($match[2]);
468-
$name = isset($a[0]) ? $a[0] : null;
469-
$attr = isset($a[1]) ? $a[1] : null;
470-
$data = isset($a[2]) ? $a[2] : [];
468+
$name = $a[0] ?? null;
469+
$attr = $a[1] ?? null;
470+
$data = $a[2] ?? [];
471471
return $this->addElement($type, $name, $attr, $data);
472472
}
473473
}

HTML/QuickForm2/Container/Group.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected function getChildValues($filtered = false)
7070
return $value;
7171

7272
} elseif (!strpos($this->getName(), '[')) {
73-
return isset($value[$this->getName()])? $value[$this->getName()]: null;
73+
return $value[$this->getName()] ?? null;
7474

7575
} else {
7676
$tokens = explode('[', str_replace(']', '', $this->getName()));
@@ -163,7 +163,7 @@ public function setValue($value)
163163
}
164164
}
165165
foreach (array_keys($nameParts) as $i) {
166-
$this->elements[$i]->setValue(isset($groupValues[$i]) ? $groupValues[$i] : null);
166+
$this->elements[$i]->setValue($groupValues[$i] ?? null);
167167
}
168168

169169
return $this;
@@ -281,11 +281,11 @@ public function removeChild(HTML_QuickForm2_Node $element)
281281
* If the reference object is not given, the element will be appended.
282282
*
283283
* @param HTML_QuickForm2_Node $element Element to insert
284-
* @param HTML_QuickForm2_Node $reference Reference to insert before
284+
* @param ?HTML_QuickForm2_Node $reference Reference to insert before
285285
*
286286
* @return HTML_QuickForm2_Node Inserted element
287287
*/
288-
public function insertBefore(HTML_QuickForm2_Node $element, HTML_QuickForm2_Node $reference = null)
288+
public function insertBefore(HTML_QuickForm2_Node $element, ?HTML_QuickForm2_Node $reference = null)
289289
{
290290
if (null === $reference) {
291291
return $this->appendChild($element);
@@ -314,7 +314,7 @@ public function setSeparator($separator)
314314
*/
315315
public function getSeparator()
316316
{
317-
return isset($this->data['separator'])? $this->data['separator']: null;
317+
return $this->data['separator'] ?? null;
318318
}
319319

320320
/**

HTML/QuickForm2/Container/Repeat.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,12 @@ public function removeChild(HTML_QuickForm2_Node $element)
208208
* Elements are kept in the prototype rather than directly in repeat
209209
*
210210
* @param HTML_QuickForm2_Node $element Element to insert
211-
* @param HTML_QuickForm2_Node $reference Reference to insert before
211+
* @param ?HTML_QuickForm2_Node $reference Reference to insert before
212212
*
213213
* @return HTML_QuickForm2_Node Inserted element
214214
*/
215215
public function insertBefore(
216-
HTML_QuickForm2_Node $element, HTML_QuickForm2_Node $reference = null
216+
HTML_QuickForm2_Node $element, ?HTML_QuickForm2_Node $reference = null
217217
) {
218218
return $this->getPrototype()->insertBefore($element, $reference);
219219
}

HTML/QuickForm2/Controller.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public function getActionName()
247247
*/
248248
public function run()
249249
{
250-
list($page, $action) = $this->getActionName();
250+
[$page, $action] = $this->getActionName();
251251
return $this->pages[$page]->handle($action);
252252
}
253253

@@ -372,12 +372,12 @@ public function nextPage(HTML_QuickForm2_Controller_Page $reference)
372372
/**
373373
* Checks whether the pages of the controller are valid
374374
*
375-
* @param HTML_QuickForm2_Controller_Page $reference If given, check only
375+
* @param ?HTML_QuickForm2_Controller_Page $reference If given, check only
376376
* the pages before (not including) that page
377377
*
378378
* @return bool
379379
*/
380-
public function isValid(HTML_QuickForm2_Controller_Page $reference = null)
380+
public function isValid(?HTML_QuickForm2_Controller_Page $reference = null)
381381
{
382382
$container = $this->getSessionContainer();
383383
foreach ($this->pages as $id => $page) {

HTML/QuickForm2/Controller/Action/Display.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ class HTML_QuickForm2_Controller_Action_Display
4444
{
4545
public function perform(HTML_QuickForm2_Controller_Page $page, $name)
4646
{
47-
$validate = false;
48-
$datasources = $page->getForm()->getDataSources();
49-
$container = $page->getController()->getSessionContainer();
50-
list(, $oldName) = $page->getController()->getActionName();
47+
$validate = false;
48+
$datasources = $page->getForm()->getDataSources();
49+
$container = $page->getController()->getSessionContainer();
50+
[, $oldName] = $page->getController()->getActionName();
5151
// Check the original action name, we need to do additional processing
5252
// if it was 'display'
5353
if ('display' == $oldName) {

HTML/QuickForm2/Controller/Action/Jump.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,20 @@ protected function resolveRelativeURL($url)
146146
}
147147
$host = $scheme . '//' . preg_replace('/:\d+$/', '', $host);
148148
$port = isset($_SERVER['SERVER_PORT']) ? (int)$_SERVER['SERVER_PORT'] : null;
149-
$base = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
149+
$base = $_SERVER['REQUEST_URI'] ?? '';
150150
if (null !== $port && $port !== ($https ? 443 : 80)) {
151151
$host .= ':' . $port;
152152
}
153153
if ('' == $url) {
154154
return $host . $base;
155155

156156
} elseif ('/' == $url[0]) {
157-
list($actPath, $actQuery) = self::splitUri($url);
157+
[$actPath, $actQuery] = self::splitUri($url);
158158
return $host . self::normalizePath($actPath) . $actQuery;
159159

160160
} else {
161-
list($basePath, $baseQuery) = self::splitUri($base);
162-
list($actPath, $actQuery) = self::splitUri($url);
161+
[$basePath,] = self::splitUri($base);
162+
[$actPath, $actQuery] = self::splitUri($url);
163163
if ('' == $actPath) {
164164
return $host . $basePath . $actQuery;
165165
} else {

HTML/QuickForm2/Element/Hierselect.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function __construct($name = null, $attributes = null, array $data = [])
117117
if (!empty($data['size'])) {
118118
$this->size = $data['size'];
119119
}
120-
$options = isset($data['options'])? $data['options']: [];
120+
$options = $data['options'] ?? [];
121121
unset($data['options'], $data['size']);
122122
parent::__construct($name, $attributes, $data);
123123
$this->loadOptions($options);

HTML/QuickForm2/Element/Select.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class HTML_QuickForm2_Element_Select extends HTML_QuickForm2_Element
9191
*/
9292
public function __construct($name = null, $attributes = null, array $data = [])
9393
{
94-
$options = isset($data['options'])? $data['options']: [];
94+
$options = $data['options'] ?? [];
9595
unset($data['options']);
9696
parent::__construct($name, $attributes, $data);
9797
$this->loadOptions($options);

HTML/QuickForm2/Factory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public static function createElement(
151151
throw new HTML_QuickForm2_InvalidArgumentException("Element type '$type' is not known");
152152
}
153153
/** @var class-string<HTML_QuickForm2_Node> $className */
154-
list($className, $includeFile) = self::$elementTypes[$type];
154+
[$className, $includeFile] = self::$elementTypes[$type];
155155
HTML_QuickForm2_Loader::loadClass($className, $includeFile, true);
156156
return new $className($name, $attributes, $data);
157157
}
@@ -206,7 +206,7 @@ public static function createRule(
206206
if (!isset(self::$registeredRules[$type])) {
207207
throw new HTML_QuickForm2_InvalidArgumentException("Rule '$type' is not known");
208208
}
209-
list($className, $includeFile, $globalConfig) = self::$registeredRules[$type];
209+
[$className, $includeFile, $globalConfig] = self::$registeredRules[$type];
210210
HTML_QuickForm2_Loader::loadClass($className, $includeFile, true);
211211
if (null !== $globalConfig) {
212212
$config = call_user_func(

0 commit comments

Comments
 (0)