Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
[cs] Use PHP short array syntax
Browse files Browse the repository at this point in the history
Since PHP 5.4 arrays can be defined with brackets ([]) instead the  function
  • Loading branch information
Maks3w authored and mwillbanks committed Jul 17, 2015
1 parent bc24894 commit 9607e2e
Show file tree
Hide file tree
Showing 143 changed files with 3,114 additions and 3,113 deletions.
1 change: 1 addition & 0 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ $config->fixers(
'object_operator',
'php_closing_tag',
'remove_lines_between_uses',
'short_array_syntax',
'short_tag',
'standardize_not_equal',
'trailing_spaces',
Expand Down
48 changes: 24 additions & 24 deletions src/Annotation/AnnotationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class AnnotationBuilder implements EventManagerAwareInterface, FormFactoryAwareI
/**
* @var array Default annotations to register
*/
protected $defaultAnnotations = array(
protected $defaultAnnotations = [
'AllowEmpty',
'Attributes',
'ComposedObject',
Expand All @@ -77,7 +77,7 @@ class AnnotationBuilder implements EventManagerAwareInterface, FormFactoryAwareI
'Type',
'ValidationGroup',
'Validator'
);
];

/**
* @var bool
Expand Down Expand Up @@ -122,10 +122,10 @@ public function setAnnotationManager(AnnotationManager $annotationManager)
*/
public function setEventManager(EventManagerInterface $events)
{
$events->setIdentifiers(array(
$events->setIdentifiers([
__CLASS__,
get_class($this),
));
]);
$events->attach(new ElementAnnotationsListener());
$events->attach(new FormAnnotationsListener());
$this->events = $events;
Expand Down Expand Up @@ -271,18 +271,18 @@ protected function configureForm($annotations, $reflection, $formSpec, $filterSp
{
$name = $this->discoverName($annotations, $reflection);
$formSpec['name'] = $name;
$formSpec['attributes'] = array();
$formSpec['elements'] = array();
$formSpec['fieldsets'] = array();
$formSpec['attributes'] = [];
$formSpec['elements'] = [];
$formSpec['fieldsets'] = [];

$events = $this->getEventManager();
foreach ($annotations as $annotation) {
$events->trigger(__FUNCTION__, $this, array(
$events->trigger(__FUNCTION__, $this, [
'annotation' => $annotation,
'name' => $name,
'formSpec' => $formSpec,
'filterSpec' => $filterSpec,
));
]);
}
}

Expand All @@ -308,24 +308,24 @@ protected function configureElement($annotations, $reflection, $formSpec, $filte
$events = $this->getEventManager();
$name = $this->discoverName($annotations, $reflection);

$elementSpec = new ArrayObject(array(
'flags' => array(),
'spec' => array(
$elementSpec = new ArrayObject([
'flags' => [],
'spec' => [
'name' => $name
),
));
$inputSpec = new ArrayObject(array(
],
]);
$inputSpec = new ArrayObject([
'name' => $name,
));
]);

$event = new Event();
$event->setParams(array(
$event->setParams([
'name' => $name,
'elementSpec' => $elementSpec,
'inputSpec' => $inputSpec,
'formSpec' => $formSpec,
'filterSpec' => $filterSpec,
));
]);
foreach ($annotations as $annotation) {
$event->setParam('annotation', $annotation);
$events->trigger(__FUNCTION__, $this, $event);
Expand All @@ -351,12 +351,12 @@ protected function configureElement($annotations, $reflection, $formSpec, $filte
// If preserve defined order is true, all elements are composed as elements to keep their ordering
if (!$this->preserveDefinedOrder() && is_subclass_of($type, 'Zend\Form\FieldsetInterface')) {
if (!isset($formSpec['fieldsets'])) {
$formSpec['fieldsets'] = array();
$formSpec['fieldsets'] = [];
}
$formSpec['fieldsets'][] = $elementSpec;
} else {
if (!isset($formSpec['elements'])) {
$formSpec['elements'] = array();
$formSpec['elements'] = [];
}
$formSpec['elements'][] = $elementSpec;
}
Expand Down Expand Up @@ -389,10 +389,10 @@ public function preserveDefinedOrder()
*/
protected function discoverName($annotations, $reflection)
{
$results = $this->getEventManager()->trigger('discoverName', $this, array(
$results = $this->getEventManager()->trigger('discoverName', $this, [
'annotations' => $annotations,
'reflection' => $reflection,
), function ($r) {
], function ($r) {
return (is_string($r) && !empty($r));
});
return $results->last();
Expand All @@ -406,9 +406,9 @@ protected function discoverName($annotations, $reflection)
*/
protected function checkForExclude($annotations)
{
$results = $this->getEventManager()->trigger('checkForExclude', $this, array(
$results = $this->getEventManager()->trigger('checkForExclude', $this, [
'annotations' => $annotations,
), function ($r) {
], function ($r) {
return (true === $r);
});
return (bool) $results->last();
Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/ComposedObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ public function isCollection()
*/
public function getOptions()
{
return is_array($this->value) && isset($this->value['options']) ? $this->value['options'] : array();
return is_array($this->value) && isset($this->value['options']) ? $this->value['options'] : [];
}
}
46 changes: 23 additions & 23 deletions src/Annotation/ElementAnnotationsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,25 @@ class ElementAnnotationsListener extends AbstractAnnotationsListener
*/
public function attach(EventManagerInterface $events)
{
$this->listeners[] = $events->attach('configureElement', array($this, 'handleAllowEmptyAnnotation'));
$this->listeners[] = $events->attach('configureElement', array($this, 'handleAttributesAnnotation'));
$this->listeners[] = $events->attach('configureElement', array($this, 'handleComposedObjectAnnotation'));
$this->listeners[] = $events->attach('configureElement', array($this, 'handleContinueIfEmptyAnnotation'));
$this->listeners[] = $events->attach('configureElement', array($this, 'handleErrorMessageAnnotation'));
$this->listeners[] = $events->attach('configureElement', array($this, 'handleFilterAnnotation'));
$this->listeners[] = $events->attach('configureElement', array($this, 'handleFlagsAnnotation'));
$this->listeners[] = $events->attach('configureElement', array($this, 'handleHydratorAnnotation'));
$this->listeners[] = $events->attach('configureElement', array($this, 'handleInputAnnotation'));
$this->listeners[] = $events->attach('configureElement', array($this, 'handleObjectAnnotation'));
$this->listeners[] = $events->attach('configureElement', array($this, 'handleOptionsAnnotation'));
$this->listeners[] = $events->attach('configureElement', array($this, 'handleRequiredAnnotation'));
$this->listeners[] = $events->attach('configureElement', array($this, 'handleTypeAnnotation'));
$this->listeners[] = $events->attach('configureElement', array($this, 'handleValidatorAnnotation'));

$this->listeners[] = $events->attach('discoverName', array($this, 'handleNameAnnotation'));
$this->listeners[] = $events->attach('discoverName', array($this, 'discoverFallbackName'));

$this->listeners[] = $events->attach('checkForExclude', array($this, 'handleExcludeAnnotation'));
$this->listeners[] = $events->attach('configureElement', [$this, 'handleAllowEmptyAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleAttributesAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleComposedObjectAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleContinueIfEmptyAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleErrorMessageAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleFilterAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleFlagsAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleHydratorAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleInputAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleObjectAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleOptionsAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleRequiredAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleTypeAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleValidatorAnnotation']);

$this->listeners[] = $events->attach('discoverName', [$this, 'handleNameAnnotation']);
$this->listeners[] = $events->attach('discoverName', [$this, 'discoverFallbackName']);

$this->listeners[] = $events->attach('checkForExclude', [$this, 'handleExcludeAnnotation']);
}

/**
Expand Down Expand Up @@ -167,7 +167,7 @@ public function handleComposedObjectAnnotation($e)
}

if (isset($elementSpec['spec']['options'])) {
$specification['options'] = isset($specification['options']) ? $specification['options'] : array();
$specification['options'] = isset($specification['options']) ? $specification['options'] : [];
$specification['options'] = array_merge($elementSpec['spec']['options'], $specification['options']);
}

Expand Down Expand Up @@ -248,7 +248,7 @@ public function handleFilterAnnotation($e)

$inputSpec = $e->getParam('inputSpec');
if (!isset($inputSpec['filters'])) {
$inputSpec['filters'] = array();
$inputSpec['filters'] = [];
}
$inputSpec['filters'][] = $annotation->getFilter();
}
Expand Down Expand Up @@ -374,7 +374,7 @@ public function handleRequiredAnnotation($e)
if ($required) {
$elementSpec = $e->getParam('elementSpec');
if (!isset($elementSpec['spec']['attributes'])) {
$elementSpec['spec']['attributes'] = array();
$elementSpec['spec']['attributes'] = [];
}

$elementSpec['spec']['attributes']['required'] = 'required';
Expand Down Expand Up @@ -417,7 +417,7 @@ public function handleValidatorAnnotation($e)

$inputSpec = $e->getParam('inputSpec');
if (!isset($inputSpec['validators'])) {
$inputSpec['validators'] = array();
$inputSpec['validators'] = [];
}
$inputSpec['validators'][] = $annotation->getValidator();
}
Expand Down
22 changes: 11 additions & 11 deletions src/Annotation/FormAnnotationsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ class FormAnnotationsListener extends AbstractAnnotationsListener
*/
public function attach(EventManagerInterface $events)
{
$this->listeners[] = $events->attach('configureForm', array($this, 'handleAttributesAnnotation'));
$this->listeners[] = $events->attach('configureForm', array($this, 'handleFlagsAnnotation'));
$this->listeners[] = $events->attach('configureForm', array($this, 'handleHydratorAnnotation'));
$this->listeners[] = $events->attach('configureForm', array($this, 'handleInputFilterAnnotation'));
$this->listeners[] = $events->attach('configureForm', array($this, 'handleObjectAnnotation'));
$this->listeners[] = $events->attach('configureForm', array($this, 'handleOptionsAnnotation'));
$this->listeners[] = $events->attach('configureForm', array($this, 'handleTypeAnnotation'));
$this->listeners[] = $events->attach('configureForm', array($this, 'handleValidationGroupAnnotation'));

$this->listeners[] = $events->attach('discoverName', array($this, 'handleNameAnnotation'));
$this->listeners[] = $events->attach('discoverName', array($this, 'discoverFallbackName'));
$this->listeners[] = $events->attach('configureForm', [$this, 'handleAttributesAnnotation']);
$this->listeners[] = $events->attach('configureForm', [$this, 'handleFlagsAnnotation']);
$this->listeners[] = $events->attach('configureForm', [$this, 'handleHydratorAnnotation']);
$this->listeners[] = $events->attach('configureForm', [$this, 'handleInputFilterAnnotation']);
$this->listeners[] = $events->attach('configureForm', [$this, 'handleObjectAnnotation']);
$this->listeners[] = $events->attach('configureForm', [$this, 'handleOptionsAnnotation']);
$this->listeners[] = $events->attach('configureForm', [$this, 'handleTypeAnnotation']);
$this->listeners[] = $events->attach('configureForm', [$this, 'handleValidationGroupAnnotation']);

$this->listeners[] = $events->attach('discoverName', [$this, 'handleNameAnnotation']);
$this->listeners[] = $events->attach('discoverName', [$this, 'discoverFallbackName']);
}

/**
Expand Down
16 changes: 8 additions & 8 deletions src/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Element implements
/**
* @var array
*/
protected $attributes = array();
protected $attributes = [];

/**
* @var null|string
Expand All @@ -32,24 +32,24 @@ class Element implements
/**
* @var array
*/
protected $labelAttributes = array();
protected $labelAttributes = [];

/**
* Label specific options
*
* @var array
*/
protected $labelOptions = array();
protected $labelOptions = [];

/**
* @var array Validation error messages
*/
protected $messages = array();
protected $messages = [];

/**
* @var array custom options
*/
protected $options = array();
protected $options = [];

/**
* @var mixed
Expand All @@ -61,7 +61,7 @@ class Element implements
* @param array $options Optional options for the element
* @throws Exception\InvalidArgumentException
*/
public function __construct($name = null, $options = array())
public function __construct($name = null, $options = [])
{
if (null !== $name) {
$this->setName($name);
Expand Down Expand Up @@ -291,7 +291,7 @@ public function removeAttributes(array $keys)
*/
public function clearAttributes()
{
$this->attributes = array();
$this->attributes = [];
return $this;
}

Expand Down Expand Up @@ -405,7 +405,7 @@ public function getLabelOptions()
*/
public function clearLabelOptions()
{
$this->labelOptions = array();
$this->labelOptions = [];
return $this;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Element/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Button extends Element
*
* @var array
*/
protected $attributes = array(
protected $attributes = [
'type' => 'button',
);
];
}
12 changes: 6 additions & 6 deletions src/Element/Captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,18 @@ public function getCaptcha()
*/
public function getInputSpecification()
{
$spec = array(
$spec = [
'name' => $this->getName(),
'required' => true,
'filters' => array(
array('name' => 'Zend\Filter\StringTrim'),
),
);
'filters' => [
['name' => 'Zend\Filter\StringTrim'],
],
];

// Test that we have a captcha before adding it to the spec
$captcha = $this->getCaptcha();
if ($captcha instanceof ZendCaptcha\AdapterInterface) {
$spec['validators'] = array($captcha);
$spec['validators'] = [$captcha];
}

return $spec;
Expand Down
Loading

0 comments on commit 9607e2e

Please sign in to comment.