Skip to content

Commit

Permalink
improved coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jun 19, 2015
1 parent 48aa5d2 commit a57a557
Show file tree
Hide file tree
Showing 62 changed files with 1,004 additions and 1,004 deletions.
6 changes: 3 additions & 3 deletions examples/basic-example.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
'qu' => 'Qumran',
'st' => 'Saint Georges Island',
],
'?' => 'other',
'?' => 'other',
];
$form->addSelect('country', 'Country:', $countries)
->setPrompt('Select your country')
Expand Down Expand Up @@ -107,8 +107,8 @@


$form->setDefaults([
'name' => 'John Doe',
'userid' => 231,
'name' => 'John Doe',
'userid' => 231,
]);


Expand Down
2 changes: 1 addition & 1 deletion examples/localization.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function translate($message, $count = NULL)
'qu' => 'Qumran',
'st' => 'Saint Georges Island',
],
'?' => 'other',
'?' => 'other',
];
$form->addSelect('country', 'Country:', $countries)
->setPrompt('Select your country');
Expand Down
2 changes: 1 addition & 1 deletion src/Bridges/FormsDI/FormsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class FormsExtension extends Nette\DI\CompilerExtension
{
public $defaults = [
'messages' => []
'messages' => [],
];


Expand Down
8 changes: 4 additions & 4 deletions src/Forms/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
class Container extends Nette\ComponentModel\Container implements \ArrayAccess
{
/** @var callable[] function(Container $sender); Occurs when the form is validated */
/** @var callable[] function (Container $sender); Occurs when the form is validated */
public $onValidate;

/** @var ControlGroup */
Expand Down Expand Up @@ -77,7 +77,7 @@ public function setValues($values, $erase = FALSE)
$control->setValue(NULL);
}

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

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

} elseif ($control instanceof Container) {
} elseif ($control instanceof self) {
$values[$name] = $control->getValues($asArray);
}
}
Expand Down Expand Up @@ -429,7 +429,7 @@ public function addImage($name, $src = NULL, $alt = NULL)
*/
public function addContainer($name)
{
$control = new Container;
$control = new self;
$control->currentGroup = $this->currentGroup;
return $this[$name] = $control;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Controls/ChoiceControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function loadHttpData()
public function setValue($value)
{
if ($value !== NULL && !array_key_exists((string) $value, $this->items)) {
$range = Nette\Utils\Strings::truncate(implode(', ', array_map(function($s) { return var_export($s, TRUE); }, array_keys($this->items))), 70, '...');
$range = Nette\Utils\Strings::truncate(implode(', ', array_map(function ($s) { return var_export($s, TRUE); }, array_keys($this->items))), 70, '...');
throw new Nette\InvalidArgumentException("Value '$value' is out of allowed range [$range] in field '{$this->name}'.");
}
$this->value = $value === NULL ? NULL : key([(string) $value => NULL]);
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Controls/MultiChoiceControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function setValue($values)
}
$values = array_keys($flip);
if ($diff = array_diff($values, array_keys($this->items))) {
$range = Nette\Utils\Strings::truncate(implode(', ', array_map(function($s) { return var_export($s, TRUE); }, array_keys($this->items))), 70, '...');
$range = Nette\Utils\Strings::truncate(implode(', ', array_map(function ($s) { return var_export($s, TRUE); }, array_keys($this->items))), 70, '...');
$vals = (count($diff) > 1 ? 's' : '') . " '" . implode("', '", $diff) . "'";
throw new Nette\InvalidArgumentException("Value$vals are out of allowed range [$range] in field '{$this->name}'.");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Controls/MultiSelectBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getControl()
$items,
[
'selected?' => $this->value,
'disabled:' => is_array($this->disabled) ? $this->disabled : NULL
'disabled:' => is_array($this->disabled) ? $this->disabled : NULL,
]
)->addAttributes(parent::getControl()->attrs)->multiple(TRUE);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Controls/SelectBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function getControl()
$items,
[
'selected?' => $this->value,
'disabled:' => is_array($this->disabled) ? $this->disabled : NULL
'disabled:' => is_array($this->disabled) ? $this->disabled : NULL,
]
)->addAttributes(parent::getControl()->attrs);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Forms/Controls/SubmitButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
*/
class SubmitButton extends Button implements Nette\Forms\ISubmitterControl
{
/** @var callable[] function(SubmitButton $sender); Occurs when the button is clicked and form is successfully validated */
/** @var callable[] function (SubmitButton $sender); Occurs when the button is clicked and form is successfully validated */
public $onClick;

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

/** @var array */
Expand Down
6 changes: 3 additions & 3 deletions src/Forms/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ class Form extends Container implements Nette\Utils\IHtmlString
/** @internal protection token ID */
const PROTECTOR_ID = '_token_';

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

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

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

/** @var mixed or NULL meaning: not detected yet */
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static function exportRules(Rules $rules)
$item = [
'op' => ($rule->isNegative ? '~' : '') . $op,
'rules' => static::exportRules($rule->branch),
'control' => $rule->control->getHtmlName()
'control' => $rule->control->getHtmlName(),
];
if ($rule->branch->getToggles()) {
$item['toggle'] = $rule->branch->getToggles();
Expand Down
4 changes: 2 additions & 2 deletions src/Forms/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ public function addFilter($filter)
Nette\Utils\Callback::check($filter);
$this->rules[] = $rule = new Rule;
$rule->control = $this->control;
$rule->validator = function($control) use ($filter) {
$control->setValue( call_user_func($filter, $control->getValue()) );
$rule->validator = function (IControl $control) use ($filter) {
$control->setValue(call_user_func($filter, $control->getValue()));
return TRUE;
};
return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function formatMessage(Rule $rule, $withValue = TRUE)
$message = $translator->translate($message, is_int($rule->arg) ? $rule->arg : NULL);
}

$message = preg_replace_callback('#%(name|label|value|\d+\$[ds]|[ds])#', function($m) use ($rule, $withValue) {
$message = preg_replace_callback('#%(name|label|value|\d+\$[ds]|[ds])#', function ($m) use ($rule, $withValue) {
static $i = -1;
switch ($m[1]) {
case 'name': return $rule->control->getName();
Expand Down
4 changes: 2 additions & 2 deletions tests/Forms.DI/FormsExtension.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use Nette\DI,
require __DIR__ . '/../bootstrap.php';


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

Expand All @@ -37,7 +37,7 @@ test(function() {
});


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

Expand Down
16 changes: 8 additions & 8 deletions tests/Forms.Latte/FormMacros.error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,36 @@ $latte = new Latte\Engine;
$latte->setLoader(new Latte\Loaders\StringLoader);
FormMacros::install($latte->getCompiler());

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

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

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


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

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


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

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

Assert::exception(function() use ($latte) {
Assert::exception(function () use ($latte) {
$latte->compile('<html>{name /}');
}, 'Latte\CompileException', 'Unknown macro {name}, use n:name attribute.');
4 changes: 2 additions & 2 deletions tests/Forms/Container.validate().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ $container->onValidate[] = function (Container $container) {
$container['name']->addError('fail 2');
};

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

Assert::same([
'Please enter a valid integer.',
'fail 1',
'fail 2'
'fail 2',
], $form->getErrors());
10 changes: 5 additions & 5 deletions tests/Forms/Container.values.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ $first->setDefaults([
],
]);

Assert::equal( ArrayHash::from([
Assert::equal(ArrayHash::from([
'name' => 'xxx',
'age' => '50',
'second' => ArrayHash::from([
'name' => 'yyy',
]),
]), $first->getValues() );
]), $first->getValues());


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


Assert::truthy( $form->isSubmitted() );
Assert::equal( ArrayHash::from([
Assert::truthy($form->isSubmitted());
Assert::equal(ArrayHash::from([
'name' => 'jim',
'first' => ArrayHash::from([
'name' => 'jim',
Expand All @@ -74,4 +74,4 @@ Assert::equal( ArrayHash::from([
'invalid' => ArrayHash::from([
'name' => '',
]),
]), $form->getValues() );
]), $form->getValues());

0 comments on commit a57a557

Please sign in to comment.