Skip to content

Commit 131f7d2

Browse files
committed
used PHP 5.4 array syntax
1 parent efe9c43 commit 131f7d2

File tree

81 files changed

+877
-877
lines changed

Some content is hidden

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

81 files changed

+877
-877
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ matrix:
1515

1616
script:
1717
- vendor/bin/tester tests -s -p php -c tests/php-unix.ini
18-
- php code-checker/src/code-checker.php -i netteForms
18+
- php temp/code-checker/src/code-checker.php --short-arrays -i netteForms
1919
- if [ $TRAVIS_PHP_VERSION == "5.6" ]; then grunt --gruntfile tests/netteForms/Gruntfile.js test; fi
2020

2121
after_failure:
@@ -25,5 +25,5 @@ after_failure:
2525
before_script:
2626
# Install Nette Tester & Code Checker
2727
- composer install --no-interaction --prefer-source
28-
- composer create-project nette/code-checker code-checker ~2.3 --no-interaction --prefer-source
28+
- composer create-project nette/code-checker temp/code-checker ~2.5 --no-interaction --prefer-source
2929
- if [ $TRAVIS_PHP_VERSION == "5.6" ]; then npm install -g grunt-cli; cd tests/netteForms; npm install; bower install; cd ../..; fi

examples/basic-example.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@
2929
$form->addText('age', 'Your age:')
3030
->setRequired('Enter your age')
3131
->addRule($form::INTEGER, 'Age must be numeric value')
32-
->addRule($form::RANGE, 'Age must be in range from %d to %d', array(10, 100));
32+
->addRule($form::RANGE, 'Age must be in range from %d to %d', [10, 100]);
3333

34-
$form->addRadioList('gender', 'Your gender:', array(
34+
$form->addRadioList('gender', 'Your gender:', [
3535
'm' => 'male',
3636
'f' => 'female',
37-
));
37+
]);
3838

39-
$form->addCheckboxList('colors', 'Favorite colors:', array(
39+
$form->addCheckboxList('colors', 'Favorite colors:', [
4040
'r' => 'red',
4141
'g' => 'green',
4242
'b' => 'blue',
43-
));
43+
]);
4444

4545
$form->addText('email', 'Email:')
4646
->setEmptyValue('@')
@@ -67,14 +67,14 @@
6767
->addConditionOn($form['send'], $form::FILLED)
6868
->setRequired('Enter your shipping address');
6969

70-
$countries = array(
71-
'World' => array(
70+
$countries = [
71+
'World' => [
7272
'bu' => 'Buranda',
7373
'qu' => 'Qumran',
7474
'st' => 'Saint Georges Island',
75-
),
75+
],
7676
'?' => 'other',
77-
);
77+
];
7878
$form->addSelect('country', 'Country:', $countries)
7979
->setPrompt('Select your country')
8080
->addConditionOn($form['send'], $form::FILLED)
@@ -106,10 +106,10 @@
106106
$form->addSubmit('submit', 'Send');
107107

108108

109-
$form->setDefaults(array(
109+
$form->setDefaults([
110110
'name' => 'John Doe',
111111
'userid' => 231,
112-
));
112+
]);
113113

114114

115115
if ($form->isSuccess()) {

examples/bootstrap2-rendering.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@
2323
$form->addText('name', 'Your name')
2424
->setRequired('Enter your name');
2525

26-
$form->addRadioList('gender', 'Your gender', array(
26+
$form->addRadioList('gender', 'Your gender', [
2727
'male', 'female',
28-
));
28+
]);
2929

30-
$form->addCheckboxList('colors', 'Favorite colors:', array(
30+
$form->addCheckboxList('colors', 'Favorite colors:', [
3131
'red', 'green', 'blue',
32-
));
32+
]);
3333

34-
$form->addSelect('country', 'Country', array(
34+
$form->addSelect('country', 'Country', [
3535
'Buranda', 'Qumran', 'Saint Georges Island',
36-
));
36+
]);
3737

3838
$form->addCheckbox('send', 'Ship to address');
3939

examples/bootstrap3-rendering.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@
2323
$form->addText('name', 'Your name')
2424
->setRequired('Enter your name');
2525

26-
$form->addRadioList('gender', 'Your gender', array(
26+
$form->addRadioList('gender', 'Your gender', [
2727
'male', 'female',
28-
));
28+
]);
2929

30-
$form->addCheckboxList('colors', 'Favorite colors:', array(
30+
$form->addCheckboxList('colors', 'Favorite colors:', [
3131
'red', 'green', 'blue',
32-
));
32+
]);
3333

34-
$form->addSelect('country', 'Country', array(
34+
$form->addSelect('country', 'Country', [
3535
'Buranda', 'Qumran', 'Saint Georges Island',
36-
));
36+
]);
3737

3838
$form->addCheckbox('send', 'Ship to address');
3939

examples/custom-control.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public function getControl()
6666
return Html::el()
6767
->add(Html::el('input')->name($name . '[day]')->id($this->getHtmlId())->value($this->day))
6868
->add(Nette\Forms\Helpers::createSelectBox(
69-
array(1 => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12),
70-
array('selected?' => $this->month)
69+
[1 => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
70+
['selected?' => $this->month]
7171
)->name($name . '[month]'))
7272
->add(Html::el('input')->name($name . '[year]')->value($this->year));
7373
}

examples/custom-rendering.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636
$form->addText('name', 'Your name')
3737
->setRequired('Enter your name');
3838

39-
$form->addRadioList('gender', 'Your gender', array(
39+
$form->addRadioList('gender', 'Your gender', [
4040
'm' => Html::el('option', 'male')->style('color: #248bd3'),
4141
'f' => Html::el('option', 'female')->style('color: #e948d4'),
42-
));
42+
]);
4343

44-
$form->addSelect('country', 'Country', array(
44+
$form->addSelect('country', 'Country', [
4545
'Buranda', 'Qumran', 'Saint Georges Island',
46-
));
46+
]);
4747

4848
$form->addCheckbox('send', 'Ship to address');
4949

examples/html5.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
->setType('number')
2929
->setDefaultValue(10)
3030
->addRule($form::INTEGER, 'Must be numeric value')
31-
->addRule($form::RANGE, 'Must be in range from %d to %d', array(1, 100));
31+
->addRule($form::RANGE, 'Must be in range from %d to %d', [1, 100]);
3232

3333
$form->addText('precision', 'Precision:')
3434
->setType('range')
3535
->setDefaultValue(50)
3636
->addRule($form::INTEGER, 'Precision must be numeric value')
37-
->addRule($form::RANGE, 'Precision must be in range from %d to %d', array(0, 100));
37+
->addRule($form::RANGE, 'Precision must be in range from %d to %d', [0, 100]);
3838

3939
$form->addText('email', 'Send to email:')
4040
->setType('email')

examples/localization.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ public function translate($message, $count = NULL)
4949
$form->addText('age', 'Your age:')
5050
->setRequired('Enter your age')
5151
->addRule($form::INTEGER, 'Age must be numeric value')
52-
->addRule($form::RANGE, 'Age must be in range from %d to %d', array(10, 100));
52+
->addRule($form::RANGE, 'Age must be in range from %d to %d', [10, 100]);
5353

54-
$countries = array(
55-
'World' => array(
54+
$countries = [
55+
'World' => [
5656
'bu' => 'Buranda',
5757
'qu' => 'Qumran',
5858
'st' => 'Saint Georges Island',
59-
),
59+
],
6060
'?' => 'other',
61-
);
61+
];
6262
$form->addSelect('country', 'Country:', $countries)
6363
->setPrompt('Select your country');
6464

examples/manual-rendering.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
$form->addText('age')
2424
->setRequired('Enter your age');
2525

26-
$form->addRadioList('gender', NULL, array(
26+
$form->addRadioList('gender', NULL, [
2727
'm' => 'male',
2828
'f' => 'female',
29-
));
29+
]);
3030

3131
$form->addText('email')
3232
->addCondition($form::FILLED)

src/Bridges/FormsDI/FormsExtension.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
*/
1919
class FormsExtension extends Nette\DI\CompilerExtension
2020
{
21-
public $defaults = array(
22-
'messages' => array()
23-
);
21+
public $defaults = [
22+
'messages' => []
23+
];
2424

2525

2626
public function afterCompile(Nette\PhpGenerator\ClassType $class)
@@ -30,9 +30,9 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class)
3030

3131
foreach ((array) $config['messages'] as $name => $text) {
3232
if (defined('Nette\Forms\Form::' . $name)) {
33-
$initialize->addBody('Nette\Forms\Validator::$messages[Nette\Forms\Form::?] = ?;', array($name, $text));
33+
$initialize->addBody('Nette\Forms\Validator::$messages[Nette\Forms\Form::?] = ?;', [$name, $text]);
3434
} elseif (defined($name)) {
35-
$initialize->addBody('Nette\Forms\Validator::$messages[' . $name . '] = ?;', array($text));
35+
$initialize->addBody('Nette\Forms\Validator::$messages[' . $name . '] = ?;', [$text]);
3636
} else {
3737
throw new Nette\InvalidArgumentException('Constant Nette\Forms\Form::' . $name . ' or constant ' . $name . ' does not exist.');
3838
}

src/Bridges/FormsLatte/FormMacros.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ class FormMacros extends MacroSet
3333
public static function install(Latte\Compiler $compiler)
3434
{
3535
$me = new static($compiler);
36-
$me->addMacro('form', array($me, 'macroForm'), 'echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd($_form)');
37-
$me->addMacro('formContainer', array($me, 'macroFormContainer'), '$formContainer = $_form = array_pop($_formStack)');
38-
$me->addMacro('label', array($me, 'macroLabel'), array($me, 'macroLabelEnd'));
39-
$me->addMacro('input', array($me, 'macroInput'), NULL, array($me, 'macroInputAttr'));
40-
$me->addMacro('name', array($me, 'macroName'), array($me, 'macroNameEnd'), array($me, 'macroNameAttr'));
41-
$me->addMacro('inputError', array($me, 'macroInputError'));
36+
$me->addMacro('form', [$me, 'macroForm'], 'echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd($_form)');
37+
$me->addMacro('formContainer', [$me, 'macroFormContainer'], '$formContainer = $_form = array_pop($_formStack)');
38+
$me->addMacro('label', [$me, 'macroLabel'], [$me, 'macroLabelEnd']);
39+
$me->addMacro('input', [$me, 'macroInput'], NULL, [$me, 'macroInputAttr']);
40+
$me->addMacro('name', [$me, 'macroName'], [$me, 'macroNameEnd'], [$me, 'macroNameAttr']);
41+
$me->addMacro('inputError', [$me, 'macroInputError']);
4242
}
4343

4444

@@ -97,7 +97,7 @@ public function macroLabel(MacroNode $node, PhpWriter $writer)
9797
. '->%1.raw) echo $_label'
9898
. ($node->tokenizer->isNext() ? '->addAttributes(%node.array)' : ''),
9999
$name,
100-
$words ? ('getLabelPart(' . implode(', ', array_map(array($writer, 'formatWord'), $words)) . ')') : 'getLabel()'
100+
$words ? ('getLabelPart(' . implode(', ', array_map([$writer, 'formatWord'], $words)) . ')') : 'getLabel()'
101101
);
102102
}
103103

@@ -129,7 +129,7 @@ public function macroInput(MacroNode $node, PhpWriter $writer)
129129
. '->%1.raw'
130130
. ($node->tokenizer->isNext() ? '->addAttributes(%node.array)' : ''),
131131
$name,
132-
$words ? 'getControlPart(' . implode(', ', array_map(array($writer, 'formatWord'), $words)) . ')' : 'getControl()'
132+
$words ? 'getControlPart(' . implode(', ', array_map([$writer, 'formatWord'], $words)) . ')' : 'getControl()'
133133
);
134134
}
135135

@@ -172,7 +172,7 @@ public function macroNameAttr(MacroNode $node, PhpWriter $writer)
172172
. ($node->htmlNode->attrs ? '->addAttributes(%2.var)' : '') . '->attributes()',
173173
$name,
174174
$words
175-
? $method . 'Part(' . implode(', ', array_map(array($writer, 'formatWord'), $words)) . ')'
175+
? $method . 'Part(' . implode(', ', array_map([$writer, 'formatWord'], $words)) . ')'
176176
: "{method_exists(\$_input, '{$method}Part')?'{$method}Part':'{$method}'}()",
177177
array_fill_keys(array_keys($node->htmlNode->attrs), NULL)
178178
);

src/Bridges/FormsLatte/Runtime.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static function renderFormEnd(Form $form, $withTags = TRUE)
5353
$parts = explode('=', $param, 2);
5454
$name = urldecode($parts[0]);
5555
if (!isset($form[$name])) {
56-
$s .= Html::el('input', array('type' => 'hidden', 'name' => $name, 'value' => urldecode($parts[1])));
56+
$s .= Html::el('input', ['type' => 'hidden', 'name' => $name, 'value' => urldecode($parts[1])]);
5757
}
5858
}
5959
}

src/Forms/Container.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function setValues($values, $erase = FALSE)
8282
$control->setValues($values[$name], $erase);
8383

8484
} elseif ($erase) {
85-
$control->setValues(array(), $erase);
85+
$control->setValues([], $erase);
8686
}
8787
}
8888
}
@@ -97,7 +97,7 @@ public function setValues($values, $erase = FALSE)
9797
*/
9898
public function getValues($asArray = FALSE)
9999
{
100-
$values = $asArray ? array() : new Nette\Utils\ArrayHash;
100+
$values = $asArray ? [] : new Nette\Utils\ArrayHash;
101101
foreach ($this->getComponents() as $name => $control) {
102102
if ($control instanceof IControl && !$control->isOmitted()) {
103103
$values[$name] = $control->getValue();
@@ -139,7 +139,7 @@ public function validate(array $controls = NULL)
139139
foreach ($controls === NULL ? $this->getComponents() : $controls as $control) {
140140
$control->validate();
141141
}
142-
foreach ($this->onValidate ?: array() as $handler) {
142+
foreach ($this->onValidate ?: [] as $handler) {
143143
$params = Nette\Utils\Callback::toReflection($handler)->getParameters();
144144
$values = isset($params[1]) ? $this->getValues($params[1]->isArray()) : NULL;
145145
Nette\Utils\Callback::invoke($handler, $this, $values);
@@ -154,7 +154,7 @@ public function validate(array $controls = NULL)
154154
*/
155155
public function getErrors()
156156
{
157-
$errors = array();
157+
$errors = [];
158158
foreach ($this->getControls() as $control) {
159159
$errors = array_merge($errors, $control->getErrors());
160160
}

src/Forms/ControlGroup.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ControlGroup extends Nette\Object
2424
protected $controls;
2525

2626
/** @var array user options */
27-
private $options = array();
27+
private $options = [];
2828

2929

3030
public function __construct()

src/Forms/Controls/BaseControl.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ abstract class BaseControl extends Nette\ComponentModel\Component implements ICo
5454
protected $label;
5555

5656
/** @var array */
57-
private $errors = array();
57+
private $errors = [];
5858

5959
/** @var bool */
6060
protected $disabled = FALSE;
@@ -69,7 +69,7 @@ abstract class BaseControl extends Nette\ComponentModel\Component implements ICo
6969
private $translator = TRUE; // means autodetect
7070

7171
/** @var array user options */
72-
private $options = array();
72+
private $options = [];
7373

7474

7575
/**
@@ -79,7 +79,7 @@ public function __construct($caption = NULL)
7979
{
8080
$this->monitor('Nette\Forms\Form');
8181
parent::__construct();
82-
$this->control = Html::el('input', array('type' => NULL, 'name' => NULL));
82+
$this->control = Html::el('input', ['type' => NULL, 'name' => NULL]);
8383
$this->label = Html::el('label');
8484
$this->caption = $caption;
8585
$this->rules = new Nette\Forms\Rules($this);
@@ -172,7 +172,7 @@ public function getValue()
172172
public function isFilled()
173173
{
174174
$value = $this->getValue();
175-
return $value !== NULL && $value !== array() && $value !== '';
175+
return $value !== NULL && $value !== [] && $value !== '';
176176
}
177177

178178

@@ -248,13 +248,13 @@ public function getControl()
248248
{
249249
$this->setOption('rendered', TRUE);
250250
$el = clone $this->control;
251-
return $el->addAttributes(array(
251+
return $el->addAttributes([
252252
'name' => $this->getHtmlName(),
253253
'id' => $this->getHtmlId(),
254254
'required' => $this->isRequired(),
255255
'disabled' => $this->isDisabled(),
256256
'data-nette-rules' => Nette\Forms\Helpers::exportRules($this->rules) ?: NULL,
257-
));
257+
]);
258258
}
259259

260260

@@ -366,7 +366,7 @@ public function getTranslator()
366366
public function translate($value, $count = NULL)
367367
{
368368
if ($translator = $this->getTranslator()) {
369-
$tmp = is_array($value) ? array(& $value) : array(array(& $value));
369+
$tmp = is_array($value) ? [& $value] : [[& $value]];
370370
foreach ($tmp[0] as & $v) {
371371
if ($v != NULL && !$v instanceof Html) { // intentionally ==
372372
$v = $translator->translate($v, $count);
@@ -509,7 +509,7 @@ public function hasErrors()
509509
*/
510510
public function cleanErrors()
511511
{
512-
$this->errors = array();
512+
$this->errors = [];
513513
}
514514

515515

0 commit comments

Comments
 (0)