Skip to content

Commit

Permalink
fixed CS
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jan 16, 2019
1 parent 65c4d82 commit b5f5dd1
Show file tree
Hide file tree
Showing 28 changed files with 746 additions and 746 deletions.
40 changes: 20 additions & 20 deletions Encoder/CsvEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,31 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
const ESCAPE_FORMULAS_KEY = 'csv_escape_formulas';
const AS_COLLECTION_KEY = 'as_collection';

private $formulasStartCharacters = array('=', '-', '+', '@');
private $defaultContext = array(
private $formulasStartCharacters = ['=', '-', '+', '@'];
private $defaultContext = [
self::DELIMITER_KEY => ',',
self::ENCLOSURE_KEY => '"',
self::ESCAPE_CHAR_KEY => '\\',
self::ESCAPE_FORMULAS_KEY => false,
self::HEADERS_KEY => array(),
self::HEADERS_KEY => [],
self::KEY_SEPARATOR_KEY => '.',
);
];

/**
* @param array $defaultContext
*/
public function __construct($defaultContext = array(), string $enclosure = '"', string $escapeChar = '\\', string $keySeparator = '.', bool $escapeFormulas = false)
public function __construct($defaultContext = [], string $enclosure = '"', string $escapeChar = '\\', string $keySeparator = '.', bool $escapeFormulas = false)
{
if (!\is_array($defaultContext)) {
@trigger_error('Passing configuration options directly to the constructor is deprecated since Symfony 4.2, use the default context instead.', E_USER_DEPRECATED);

$defaultContext = array(
$defaultContext = [
self::DELIMITER_KEY => (string) $defaultContext,
self::ENCLOSURE_KEY => $enclosure,
self::ESCAPE_CHAR_KEY => $escapeChar,
self::KEY_SEPARATOR_KEY => $keySeparator,
self::ESCAPE_FORMULAS_KEY => $escapeFormulas,
);
];
}

$this->defaultContext = array_merge($this->defaultContext, $defaultContext);
Expand All @@ -63,20 +63,20 @@ public function __construct($defaultContext = array(), string $enclosure = '"',
/**
* {@inheritdoc}
*/
public function encode($data, $format, array $context = array())
public function encode($data, $format, array $context = [])
{
$handle = fopen('php://temp,', 'w+');

if (!\is_array($data)) {
$data = array(array($data));
$data = [[$data]];
} elseif (empty($data)) {
$data = array(array());
$data = [[]];
} else {
// Sequential arrays of arrays are considered as collections
$i = 0;
foreach ($data as $key => $value) {
if ($i !== $key || !\is_array($value)) {
$data = array($data);
$data = [$data];
break;
}

Expand All @@ -87,7 +87,7 @@ public function encode($data, $format, array $context = array())
list($delimiter, $enclosure, $escapeChar, $keySeparator, $headers, $escapeFormulas) = $this->getCsvOptions($context);

foreach ($data as &$value) {
$flattened = array();
$flattened = [];
$this->flatten($value, $flattened, $keySeparator, '', $escapeFormulas);
$value = $flattened;
}
Expand Down Expand Up @@ -120,16 +120,16 @@ public function supportsEncoding($format)
/**
* {@inheritdoc}
*/
public function decode($data, $format, array $context = array())
public function decode($data, $format, array $context = [])
{
$handle = fopen('php://temp', 'r+');
fwrite($handle, $data);
rewind($handle);

$headers = null;
$nbHeaders = 0;
$headerCount = array();
$result = array();
$headerCount = [];
$result = [];

list($delimiter, $enclosure, $escapeChar, $keySeparator) = $this->getCsvOptions($context);

Expand All @@ -148,7 +148,7 @@ public function decode($data, $format, array $context = array())
continue;
}

$item = array();
$item = [];
for ($i = 0; ($i < $nbCols) && ($i < $nbHeaders); ++$i) {
$depth = $headerCount[$i];
$arr = &$item;
Expand All @@ -161,7 +161,7 @@ public function decode($data, $format, array $context = array())
}

if (!isset($arr[$headers[$i][$j]])) {
$arr[$headers[$i][$j]] = array();
$arr[$headers[$i][$j]] = [];
}

$arr = &$arr[$headers[$i][$j]];
Expand Down Expand Up @@ -227,16 +227,16 @@ private function getCsvOptions(array $context): array
throw new InvalidArgumentException(sprintf('The "%s" context variable must be an array or null, given "%s".', self::HEADERS_KEY, \gettype($headers)));
}

return array($delimiter, $enclosure, $escapeChar, $keySeparator, $headers, $escapeFormulas);
return [$delimiter, $enclosure, $escapeChar, $keySeparator, $headers, $escapeFormulas];
}

/**
* @return string[]
*/
private function extractHeaders(array $data)
{
$headers = array();
$flippedHeaders = array();
$headers = [];
$flippedHeaders = [];

foreach ($data as $row) {
$previousHeader = null;
Expand Down
12 changes: 6 additions & 6 deletions Encoder/JsonDecode.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,26 @@ class JsonDecode implements DecoderInterface
*/
const RECURSION_DEPTH = 'json_decode_recursion_depth';

private $defaultContext = array(
private $defaultContext = [
self::ASSOCIATIVE => false,
self::OPTIONS => 0,
self::RECURSION_DEPTH => 512,
);
];

/**
* Constructs a new JsonDecode instance.
*
* @param array $defaultContext
*/
public function __construct($defaultContext = array(), int $depth = 512)
public function __construct($defaultContext = [], int $depth = 512)
{
if (!\is_array($defaultContext)) {
@trigger_error(sprintf('Using constructor parameters that are not a default context is deprecated since Symfony 4.2, use the "%s" and "%s" keys of the context instead.', self::ASSOCIATIVE, self::RECURSION_DEPTH), E_USER_DEPRECATED);

$defaultContext = array(
$defaultContext = [
self::ASSOCIATIVE => (bool) $defaultContext,
self::RECURSION_DEPTH => $depth,
);
];
}

$this->defaultContext = array_merge($this->defaultContext, $defaultContext);
Expand Down Expand Up @@ -86,7 +86,7 @@ public function __construct($defaultContext = array(), int $depth = 512)
*
* @see http://php.net/json_decode json_decode
*/
public function decode($data, $format, array $context = array())
public function decode($data, $format, array $context = [])
{
$associative = $context[self::ASSOCIATIVE] ?? $this->defaultContext[self::ASSOCIATIVE];
$recursionDepth = $context[self::RECURSION_DEPTH] ?? $this->defaultContext[self::RECURSION_DEPTH];
Expand Down
8 changes: 4 additions & 4 deletions Encoder/JsonEncode.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ class JsonEncode implements EncoderInterface
{
const OPTIONS = 'json_encode_options';

private $defaultContext = array(
private $defaultContext = [
self::OPTIONS => 0,
);
];

/**
* @param array $defaultContext
*/
public function __construct($defaultContext = array())
public function __construct($defaultContext = [])
{
if (!\is_array($defaultContext)) {
@trigger_error(sprintf('Passing an integer as first parameter of the "%s()" method is deprecated since Symfony 4.2, use the "json_encode_options" key of the context instead.', __METHOD__), E_USER_DEPRECATED);
Expand All @@ -45,7 +45,7 @@ public function __construct($defaultContext = array())
*
* {@inheritdoc}
*/
public function encode($data, $format, array $context = array())
public function encode($data, $format, array $context = [])
{
$jsonEncodeOptions = $context[self::OPTIONS] ?? $this->defaultContext[self::OPTIONS];
$encodedJson = json_encode($data, $jsonEncodeOptions);
Expand Down
2 changes: 1 addition & 1 deletion Encoder/JsonEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class JsonEncoder implements EncoderInterface, DecoderInterface
public function __construct(JsonEncode $encodingImpl = null, JsonDecode $decodingImpl = null)
{
$this->encodingImpl = $encodingImpl ?: new JsonEncode();
$this->decodingImpl = $decodingImpl ?: new JsonDecode(array(JsonDecode::ASSOCIATIVE => true));
$this->decodingImpl = $decodingImpl ?: new JsonDecode([JsonDecode::ASSOCIATIVE => true]);
}

/**
Expand Down
40 changes: 20 additions & 20 deletions Encoder/XmlEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
const TYPE_CASE_ATTRIBUTES = 'xml_type_cast_attributes';
const VERSION = 'xml_version';

private $defaultContext = array(
private $defaultContext = [
self::AS_COLLECTION => false,
self::DECODER_IGNORED_NODE_TYPES => array(XML_PI_NODE, XML_COMMENT_NODE),
self::ENCODER_IGNORED_NODE_TYPES => array(),
self::DECODER_IGNORED_NODE_TYPES => [XML_PI_NODE, XML_COMMENT_NODE],
self::ENCODER_IGNORED_NODE_TYPES => [],
self::LOAD_OPTIONS => LIBXML_NONET | LIBXML_NOBLANKS,
self::REMOVE_EMPTY_TAGS => false,
self::ROOT_NODE_NAME => 'response',
self::TYPE_CASE_ATTRIBUTES => true,
);
];

/**
* @var \DOMDocument
Expand All @@ -74,17 +74,17 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
/**
* @param array $defaultContext
*/
public function __construct($defaultContext = array(), int $loadOptions = null, array $decoderIgnoredNodeTypes = array(XML_PI_NODE, XML_COMMENT_NODE), array $encoderIgnoredNodeTypes = array())
public function __construct($defaultContext = [], int $loadOptions = null, array $decoderIgnoredNodeTypes = [XML_PI_NODE, XML_COMMENT_NODE], array $encoderIgnoredNodeTypes = [])
{
if (!\is_array($defaultContext)) {
@trigger_error('Passing configuration options directly to the constructor is deprecated since Symfony 4.2, use the default context instead.', E_USER_DEPRECATED);

$defaultContext = array(
$defaultContext = [
self::DECODER_IGNORED_NODE_TYPES => $decoderIgnoredNodeTypes,
self::ENCODER_IGNORED_NODE_TYPES => $encoderIgnoredNodeTypes,
self::LOAD_OPTIONS => $loadOptions ?? LIBXML_NONET | LIBXML_NOBLANKS,
self::ROOT_NODE_NAME => (string) $defaultContext,
);
];
}

$this->defaultContext = array_merge($this->defaultContext, $defaultContext);
Expand All @@ -93,7 +93,7 @@ public function __construct($defaultContext = array(), int $loadOptions = null,
/**
* {@inheritdoc}
*/
public function encode($data, $format, array $context = array())
public function encode($data, $format, array $context = [])
{
$encoderIgnoredNodeTypes = $context[self::ENCODER_IGNORED_NODE_TYPES] ?? $this->defaultContext[self::ENCODER_IGNORED_NODE_TYPES];
$ignorePiNode = \in_array(XML_PI_NODE, $encoderIgnoredNodeTypes, true);
Expand Down Expand Up @@ -121,7 +121,7 @@ public function encode($data, $format, array $context = array())
/**
* {@inheritdoc}
*/
public function decode($data, $format, array $context = array())
public function decode($data, $format, array $context = [])
{
if ('' === trim($data)) {
throw new NotEncodableValueException('Invalid XML data, it can not be empty.');
Expand Down Expand Up @@ -158,7 +158,7 @@ public function decode($data, $format, array $context = array())

if ($rootNode->hasChildNodes()) {
$xpath = new \DOMXPath($dom);
$data = array();
$data = [];
foreach ($xpath->query('namespace::*', $dom->documentElement) as $nsNode) {
$data['@'.$nsNode->nodeName] = $nsNode->nodeValue;
}
Expand All @@ -176,7 +176,7 @@ public function decode($data, $format, array $context = array())
return $rootNode->nodeValue;
}

$data = array();
$data = [];

foreach ($rootNode->attributes as $attrKey => $attr) {
$data['@'.$attrKey] = $attr->nodeValue;
Expand Down Expand Up @@ -297,7 +297,7 @@ final protected function isElementNameValid(string $name): bool
*
* @return array|string
*/
private function parseXml(\DOMNode $node, array $context = array())
private function parseXml(\DOMNode $node, array $context = [])
{
$data = $this->parseXmlAttributes($node, $context);

Expand Down Expand Up @@ -329,13 +329,13 @@ private function parseXml(\DOMNode $node, array $context = array())
/**
* Parse the input DOMNode attributes into an array.
*/
private function parseXmlAttributes(\DOMNode $node, array $context = array()): array
private function parseXmlAttributes(\DOMNode $node, array $context = []): array
{
if (!$node->hasAttributes()) {
return array();
return [];
}

$data = array();
$data = [];
$typeCastAttributes = (bool) ($context[self::TYPE_CASE_ATTRIBUTES] ?? $this->defaultContext[self::TYPE_CASE_ATTRIBUTES]);

foreach ($node->attributes as $attr) {
Expand All @@ -362,17 +362,17 @@ private function parseXmlAttributes(\DOMNode $node, array $context = array()): a
*
* @return array|string
*/
private function parseXmlValue(\DOMNode $node, array $context = array())
private function parseXmlValue(\DOMNode $node, array $context = [])
{
if (!$node->hasChildNodes()) {
return $node->nodeValue;
}

if (1 === $node->childNodes->length && \in_array($node->firstChild->nodeType, array(XML_TEXT_NODE, XML_CDATA_SECTION_NODE))) {
if (1 === $node->childNodes->length && \in_array($node->firstChild->nodeType, [XML_TEXT_NODE, XML_CDATA_SECTION_NODE])) {
return $node->firstChild->nodeValue;
}

$value = array();
$value = [];
$decoderIgnoredNodeTypes = $context[self::DECODER_IGNORED_NODE_TYPES] ?? $this->defaultContext[self::DECODER_IGNORED_NODE_TYPES];
foreach ($node->childNodes as $subnode) {
if (\in_array($subnode->nodeType, $decoderIgnoredNodeTypes, true)) {
Expand Down Expand Up @@ -539,7 +539,7 @@ private function createDomDocument(array $context): \DOMDocument
$document = new \DOMDocument();

// Set an attribute on the DOM document specifying, as part of the XML declaration,
$xmlOptions = array(
$xmlOptions = [
// nicely formats output with indentation and extra space
self::FORMAT_OUTPUT => 'formatOutput',
// the version number of the document
Expand All @@ -548,7 +548,7 @@ private function createDomDocument(array $context): \DOMDocument
self::ENCODING => 'encoding',
// whether the document is standalone
self::STANDALONE => 'xmlStandalone',
);
];
foreach ($xmlOptions as $xmlOption => $documentProperty) {
if ($contextOption = $context[$xmlOption] ?? $this->defaultContext[$xmlOption] ?? false) {
$document->$documentProperty = $contextOption;
Expand Down
4 changes: 2 additions & 2 deletions Mapping/AttributeMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AttributeMetadata implements AttributeMetadataInterface
* class' serialized representation. Do not access it. Use
* {@link getGroups()} instead.
*/
public $groups = array();
public $groups = [];

/**
* @var int|null
Expand Down Expand Up @@ -140,6 +140,6 @@ public function merge(AttributeMetadataInterface $attributeMetadata)
*/
public function __sleep()
{
return array('name', 'groups', 'maxDepth', 'serializedName');
return ['name', 'groups', 'maxDepth', 'serializedName'];
}
}
4 changes: 2 additions & 2 deletions NameConverter/AdvancedNameConverterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ interface AdvancedNameConverterInterface extends NameConverterInterface
/**
* {@inheritdoc}
*/
public function normalize($propertyName, string $class = null, string $format = null, array $context = array());
public function normalize($propertyName, string $class = null, string $format = null, array $context = []);

/**
* {@inheritdoc}
*/
public function denormalize($propertyName, string $class = null, string $format = null, array $context = array());
public function denormalize($propertyName, string $class = null, string $format = null, array $context = []);
}

0 comments on commit b5f5dd1

Please sign in to comment.