cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,19 +1,24 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\DocGeneratorBundle\Serializer\Encoder;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
use function array_keys;
use function is_array;
class DocGenEncoder implements \Symfony\Component\Serializer\Encoder\EncoderInterface
{
/**
* @inheritDoc
*/
public function encode($data, string $format, array $context = [])
{
if (!$this->isAssociative($data)) {
throw new UnexpectedValueException("Only associative arrays are allowed; lists are not allowed");
throw new UnexpectedValueException('Only associative arrays are allowed; lists are not allowed');
}
$result = [];
@@ -22,11 +27,28 @@ class DocGenEncoder implements \Symfony\Component\Serializer\Encoder\EncoderInte
return $result;
}
public function supportsEncoding(string $format)
{
return 'docgen' === $format;
}
private function canonicalizeKey(string $path, string $key): string
{
return '' === $path ? $key : $path . '_' . $key;
}
private function isAssociative(array $data)
{
$keys = array_keys($data);
return array_keys($keys) !== $keys;
}
private function recusiveEncoding(array $data, array &$result, $path)
{
if ($this->isAssociative($data)) {
foreach ($data as $key => $value) {
if (\is_array($value)) {
if (is_array($value)) {
$this->recusiveEncoding($value, $result, $this->canonicalizeKey($path, $key));
} else {
$result[$this->canonicalizeKey($path, $key)] = $value;
@@ -34,9 +56,8 @@ class DocGenEncoder implements \Symfony\Component\Serializer\Encoder\EncoderInte
}
} else {
foreach ($data as $elem) {
if (!$this->isAssociative($elem)) {
throw new UnexpectedValueException(sprintf("Embedded loops are not allowed. See data under %s path", $path));
throw new UnexpectedValueException(sprintf('Embedded loops are not allowed. See data under %s path', $path));
}
$sub = [];
@@ -45,25 +66,4 @@ class DocGenEncoder implements \Symfony\Component\Serializer\Encoder\EncoderInte
}
}
}
private function canonicalizeKey(string $path, string $key): string
{
return $path === '' ? $key : $path.'_'.$key;
}
private function isAssociative(array $data)
{
$keys = \array_keys($data);
return $keys !== \array_keys($keys);
}
/**
* @inheritDoc
*/
public function supportsEncoding(string $format)
{
return $format === 'docgen';
}
}