Skip to content

Commit a57a557

Browse files
committed
improved coding style
1 parent 48aa5d2 commit a57a557

File tree

62 files changed

+1004
-1004
lines changed

Some content is hidden

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

62 files changed

+1004
-1004
lines changed

examples/basic-example.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
'qu' => 'Qumran',
7474
'st' => 'Saint Georges Island',
7575
],
76-
'?' => 'other',
76+
'?' => 'other',
7777
];
7878
$form->addSelect('country', 'Country:', $countries)
7979
->setPrompt('Select your country')
@@ -107,8 +107,8 @@
107107

108108

109109
$form->setDefaults([
110-
'name' => 'John Doe',
111-
'userid' => 231,
110+
'name' => 'John Doe',
111+
'userid' => 231,
112112
]);
113113

114114

examples/localization.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function translate($message, $count = NULL)
5757
'qu' => 'Qumran',
5858
'st' => 'Saint Georges Island',
5959
],
60-
'?' => 'other',
60+
'?' => 'other',
6161
];
6262
$form->addSelect('country', 'Country:', $countries)
6363
->setPrompt('Select your country');

src/Bridges/FormsDI/FormsExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
class FormsExtension extends Nette\DI\CompilerExtension
2020
{
2121
public $defaults = [
22-
'messages' => []
22+
'messages' => [],
2323
];
2424

2525

src/Forms/Container.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
class Container extends Nette\ComponentModel\Container implements \ArrayAccess
2626
{
27-
/** @var callable[] function(Container $sender); Occurs when the form is validated */
27+
/** @var callable[] function (Container $sender); Occurs when the form is validated */
2828
public $onValidate;
2929

3030
/** @var ControlGroup */
@@ -77,7 +77,7 @@ public function setValues($values, $erase = FALSE)
7777
$control->setValue(NULL);
7878
}
7979

80-
} elseif ($control instanceof Container) {
80+
} elseif ($control instanceof self) {
8181
if (array_key_exists($name, $values)) {
8282
$control->setValues($values[$name], $erase);
8383

@@ -102,7 +102,7 @@ public function getValues($asArray = FALSE)
102102
if ($control instanceof IControl && !$control->isOmitted()) {
103103
$values[$name] = $control->getValue();
104104

105-
} elseif ($control instanceof Container) {
105+
} elseif ($control instanceof self) {
106106
$values[$name] = $control->getValues($asArray);
107107
}
108108
}
@@ -429,7 +429,7 @@ public function addImage($name, $src = NULL, $alt = NULL)
429429
*/
430430
public function addContainer($name)
431431
{
432-
$control = new Container;
432+
$control = new self;
433433
$control->currentGroup = $this->currentGroup;
434434
return $this[$name] = $control;
435435
}

src/Forms/Controls/ChoiceControl.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function loadHttpData()
5959
public function setValue($value)
6060
{
6161
if ($value !== NULL && !array_key_exists((string) $value, $this->items)) {
62-
$range = Nette\Utils\Strings::truncate(implode(', ', array_map(function($s) { return var_export($s, TRUE); }, array_keys($this->items))), 70, '...');
62+
$range = Nette\Utils\Strings::truncate(implode(', ', array_map(function ($s) { return var_export($s, TRUE); }, array_keys($this->items))), 70, '...');
6363
throw new Nette\InvalidArgumentException("Value '$value' is out of allowed range [$range] in field '{$this->name}'.");
6464
}
6565
$this->value = $value === NULL ? NULL : key([(string) $value => NULL]);

src/Forms/Controls/MultiChoiceControl.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function setValue($values)
6868
}
6969
$values = array_keys($flip);
7070
if ($diff = array_diff($values, array_keys($this->items))) {
71-
$range = Nette\Utils\Strings::truncate(implode(', ', array_map(function($s) { return var_export($s, TRUE); }, array_keys($this->items))), 70, '...');
71+
$range = Nette\Utils\Strings::truncate(implode(', ', array_map(function ($s) { return var_export($s, TRUE); }, array_keys($this->items))), 70, '...');
7272
$vals = (count($diff) > 1 ? 's' : '') . " '" . implode("', '", $diff) . "'";
7373
throw new Nette\InvalidArgumentException("Value$vals are out of allowed range [$range] in field '{$this->name}'.");
7474
}

src/Forms/Controls/MultiSelectBox.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function getControl()
6161
$items,
6262
[
6363
'selected?' => $this->value,
64-
'disabled:' => is_array($this->disabled) ? $this->disabled : NULL
64+
'disabled:' => is_array($this->disabled) ? $this->disabled : NULL,
6565
]
6666
)->addAttributes(parent::getControl()->attrs)->multiple(TRUE);
6767
}

src/Forms/Controls/SelectBox.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function getControl()
9191
$items,
9292
[
9393
'selected?' => $this->value,
94-
'disabled:' => is_array($this->disabled) ? $this->disabled : NULL
94+
'disabled:' => is_array($this->disabled) ? $this->disabled : NULL,
9595
]
9696
)->addAttributes(parent::getControl()->attrs);
9797
}

src/Forms/Controls/SubmitButton.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
*/
2121
class SubmitButton extends Button implements Nette\Forms\ISubmitterControl
2222
{
23-
/** @var callable[] function(SubmitButton $sender); Occurs when the button is clicked and form is successfully validated */
23+
/** @var callable[] function (SubmitButton $sender); Occurs when the button is clicked and form is successfully validated */
2424
public $onClick;
2525

26-
/** @var callable[] function(SubmitButton $sender); Occurs when the button is clicked and form is not validated */
26+
/** @var callable[] function (SubmitButton $sender); Occurs when the button is clicked and form is not validated */
2727
public $onInvalidClick;
2828

2929
/** @var array */

src/Forms/Form.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ class Form extends Container implements Nette\Utils\IHtmlString
8383
/** @internal protection token ID */
8484
const PROTECTOR_ID = '_token_';
8585

86-
/** @var callable[] function(Form $sender); Occurs when the form is submitted and successfully validated */
86+
/** @var callable[] function (Form $sender); Occurs when the form is submitted and successfully validated */
8787
public $onSuccess;
8888

89-
/** @var callable[] function(Form $sender); Occurs when the form is submitted and is not valid */
89+
/** @var callable[] function (Form $sender); Occurs when the form is submitted and is not valid */
9090
public $onError;
9191

92-
/** @var callable[] function(Form $sender); Occurs when the form is submitted */
92+
/** @var callable[] function (Form $sender); Occurs when the form is submitted */
9393
public $onSubmit;
9494

9595
/** @var mixed or NULL meaning: not detected yet */

src/Forms/Helpers.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public static function exportRules(Rules $rules)
110110
$item = [
111111
'op' => ($rule->isNegative ? '~' : '') . $op,
112112
'rules' => static::exportRules($rule->branch),
113-
'control' => $rule->control->getHtmlName()
113+
'control' => $rule->control->getHtmlName(),
114114
];
115115
if ($rule->branch->getToggles()) {
116116
$item['toggle'] = $rule->branch->getToggles();

src/Forms/Rules.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ public function addFilter($filter)
161161
Nette\Utils\Callback::check($filter);
162162
$this->rules[] = $rule = new Rule;
163163
$rule->control = $this->control;
164-
$rule->validator = function($control) use ($filter) {
165-
$control->setValue( call_user_func($filter, $control->getValue()) );
164+
$rule->validator = function (IControl $control) use ($filter) {
165+
$control->setValue(call_user_func($filter, $control->getValue()));
166166
return TRUE;
167167
};
168168
return $this;

src/Forms/Validator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static function formatMessage(Rule $rule, $withValue = TRUE)
6262
$message = $translator->translate($message, is_int($rule->arg) ? $rule->arg : NULL);
6363
}
6464

65-
$message = preg_replace_callback('#%(name|label|value|\d+\$[ds]|[ds])#', function($m) use ($rule, $withValue) {
65+
$message = preg_replace_callback('#%(name|label|value|\d+\$[ds]|[ds])#', function ($m) use ($rule, $withValue) {
6666
static $i = -1;
6767
switch ($m[1]) {
6868
case 'name': return $rule->control->getName();

tests/Forms.DI/FormsExtension.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use Nette\DI,
1414
require __DIR__ . '/../bootstrap.php';
1515

1616

17-
test(function() {
17+
test(function () {
1818
$compiler = new DI\Compiler;
1919
$compiler->addExtension('forms', new FormsExtension);
2020

@@ -37,7 +37,7 @@ test(function() {
3737
});
3838

3939

40-
Assert::exception(function() {
40+
Assert::exception(function () {
4141
$compiler = new DI\Compiler;
4242
$compiler->addExtension('forms', new FormsExtension);
4343

tests/Forms.Latte/FormMacros.error.phpt

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,36 @@ $latte = new Latte\Engine;
1616
$latte->setLoader(new Latte\Loaders\StringLoader);
1717
FormMacros::install($latte->getCompiler());
1818

19-
Assert::exception(function() use ($latte) {
19+
Assert::exception(function () use ($latte) {
2020
$latte->compile('<form n:form></form>');
2121
}, 'Latte\CompileException', 'Did you mean <form n:name=...> ?');
2222

23-
Assert::exception(function() use ($latte) {
23+
Assert::exception(function () use ($latte) {
2424
$latte->compile('<form n:name></form>');
2525
}, 'Latte\CompileException', 'Missing name in n:name.');
2626

27-
Assert::exception(function() use ($latte) {
27+
Assert::exception(function () use ($latte) {
2828
$latte->compile('<form n:inner-name></form>');
2929
}, 'Latte\CompileException', 'Unknown attribute n:inner-name, use n:name attribute.');
3030

3131

32-
Assert::exception(function() use ($latte) {
32+
Assert::exception(function () use ($latte) {
3333
$latte->compile('<html>{form /}');
3434
}, 'Latte\CompileException', 'Missing form name in {form}.');
3535

36-
Assert::exception(function() use ($latte) {
36+
Assert::exception(function () use ($latte) {
3737
$latte->compile('<html>{formContainer /}');
3838
}, 'Latte\CompileException', 'Missing name in {formContainer}.');
3939

4040

41-
Assert::exception(function() use ($latte) {
41+
Assert::exception(function () use ($latte) {
4242
$latte->compile('<html>{label /}');
4343
}, 'Latte\CompileException', 'Missing name in {label}.');
4444

45-
Assert::exception(function() use ($latte) {
45+
Assert::exception(function () use ($latte) {
4646
$latte->compile('<html>{input /}');
4747
}, 'Latte\CompileException', 'Missing name in {input}.');
4848

49-
Assert::exception(function() use ($latte) {
49+
Assert::exception(function () use ($latte) {
5050
$latte->compile('<html>{name /}');
5151
}, 'Latte\CompileException', 'Unknown macro {name}, use n:name attribute.');

tests/Forms/Container.validate().phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ $container->onValidate[] = function (Container $container) {
2424
$container['name']->addError('fail 2');
2525
};
2626

27-
$form->setValues(['name' => "invalid*input"]);
27+
$form->setValues(['name' => 'invalid*input']);
2828
$form->validate();
2929

3030
Assert::same([
3131
'Please enter a valid integer.',
3232
'fail 1',
33-
'fail 2'
33+
'fail 2',
3434
], $form->getErrors());

tests/Forms/Container.values.phpt

+5-5
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ $first->setDefaults([
4444
],
4545
]);
4646

47-
Assert::equal( ArrayHash::from([
47+
Assert::equal(ArrayHash::from([
4848
'name' => 'xxx',
4949
'age' => '50',
5050
'second' => ArrayHash::from([
5151
'name' => 'yyy',
5252
]),
53-
]), $first->getValues() );
53+
]), $first->getValues());
5454

5555

5656
$form = new Form;
@@ -61,8 +61,8 @@ $invalid->addText('name');
6161
$form->addSubmit('send');
6262

6363

64-
Assert::truthy( $form->isSubmitted() );
65-
Assert::equal( ArrayHash::from([
64+
Assert::truthy($form->isSubmitted());
65+
Assert::equal(ArrayHash::from([
6666
'name' => 'jim',
6767
'first' => ArrayHash::from([
6868
'name' => 'jim',
@@ -74,4 +74,4 @@ Assert::equal( ArrayHash::from([
7474
'invalid' => ArrayHash::from([
7575
'name' => '',
7676
]),
77-
]), $form->getValues() );
77+
]), $form->getValues());

0 commit comments

Comments
 (0)