Skip to content

Commit

Permalink
Merge 2.x into 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
SonataCI committed May 2, 2022
2 parents 67120b0 + 18335df commit d220cf8
Show file tree
Hide file tree
Showing 44 changed files with 171 additions and 128 deletions.
5 changes: 4 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
includes:
- phpstan-baseline.neon
- vendor/phpstan/phpstan/conf/bleedingEdge.neon

parameters:
level: 5
level: 6
paths:
- src
- tests
treatPhpDocTypesAsCertain: false
checkGenericClassInNonGenericObjectType: true
checkInternalClassCaseSensitivity: true
checkMissingIterableValueType: true
checkMissingVarTagTypehint: true
checkMissingTypehints: true
checkUninitializedProperties: true
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" errorLevel="5" findUnusedPsalmSuppress="true" resolveFromConfigFile="true" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" errorLevel="4" findUnusedPsalmSuppress="true" resolveFromConfigFile="true" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">
<projectFiles>
<directory name="src"/>
<directory name="tests"/>
Expand Down
4 changes: 2 additions & 2 deletions src/Bridge/Symfony/Bundle/SonataExporterBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
ForwardCompatibleSonataExporterBundle::class
), \E_USER_DEPRECATED);

// @phpstan-ignore-next-line
if (false) {
/** @psalm-suppress TypeDoesNotContainType */
if (false) { // @phpstan-ignore-line
/**
* NEXT_MAJOR: remove this class.
*
Expand Down
3 changes: 3 additions & 0 deletions src/Bridge/Symfony/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ public function getConfigTreeBuilder(): TreeBuilder
return $treeBuilder;
}

/**
* @return string[]
*/
private function getDefaultWriters(): array
{
$fields = ['csv', 'json', 'xls', 'xml'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
*/
final class SonataExporterExtension extends Extension
{
/**
* @param array<mixed> $configs
*/
public function load(array $configs, ContainerBuilder $container): void
{
$processor = new Processor();
Expand All @@ -37,6 +40,9 @@ public function load(array $configs, ContainerBuilder $container): void
$this->configureWriters($container, $config['writers']);
}

/**
* @param array<string, array<string>> $config
*/
private function configureExporter(ContainerBuilder $container, array $config): void
{
foreach (['csv', 'json', 'xls', 'xlsx', 'xml'] as $format) {
Expand All @@ -48,6 +54,9 @@ private function configureExporter(ContainerBuilder $container, array $config):
}
}

/**
* @param array<string, array<string, mixed>> $config
*/
private function configureWriters(ContainerBuilder $container, array $config): void
{
foreach ($config as $format => $settings) {
Expand Down
4 changes: 2 additions & 2 deletions src/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
final class Exporter
{
/**
* @var TypedWriterInterface[]
* @var array<TypedWriterInterface>
*/
private $writers;

/**
* @param TypedWriterInterface[] $writers an array of allowed typed writers, indexed by format name
* @param array<TypedWriterInterface> $writers an array of allowed typed writers, indexed by format name
*/
public function __construct(array $writers = [])
{
Expand Down
11 changes: 9 additions & 2 deletions src/Source/AbstractXmlSourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ abstract class AbstractXmlSourceIterator implements SourceIteratorInterface
protected $currentRow;

/**
* @var array
* @var array<string, array<string>>
*/
protected $bufferedRow = [];

Expand All @@ -86,21 +86,28 @@ public function __construct(string $filename, bool $hasHeaders = true)
/**
* Start element handler.
*
* @param resource $parser
* @param resource $parser
* @param array<string, string> $attributes
*
* @return void
*/
abstract public function tagStart($parser, string $name, array $attributes = []);

/**
* End element handler.
*
* @param resource $parser
*
* @return void
*/
abstract public function tagEnd($parser, string $name);

/**
* Tag content handler.
*
* @param resource $parser
*
* @return void
*/
abstract public function tagContent($parser, string $data);

Expand Down
3 changes: 3 additions & 0 deletions src/Source/ArraySourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

final class ArraySourceIterator extends IteratorSourceIterator
{
/**
* @param array<mixed> $data
*/
public function __construct(array $data)
{
parent::__construct(new \ArrayIterator($data));
Expand Down
6 changes: 3 additions & 3 deletions src/Source/CsvSourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ final class CsvSourceIterator implements SourceIteratorInterface
private $hasHeaders;

/**
* @var array
* @var array<string|null>
*/
private $columns = [];

Expand All @@ -63,7 +63,7 @@ final class CsvSourceIterator implements SourceIteratorInterface
private $position = 0;

/**
* @var array|false
* @var array<string|null>|false
*/
private $currentLine = [];

Expand All @@ -82,7 +82,7 @@ public function __construct(
}

/**
* @return array
* @return array<string|null>
*/
#[\ReturnTypeWillChange]
public function current()
Expand Down
3 changes: 3 additions & 0 deletions src/Source/DoctrineORMQuerySourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ final public function rewind(): void
$this->iterator->rewind();
}

/**
* @param iterable<mixed> $iterable
*/
private function iterableToIterator(iterable $iterable): \Iterator
{
if ($iterable instanceof \Iterator) {
Expand Down
11 changes: 9 additions & 2 deletions src/Source/PropelCollectionSourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@

namespace Sonata\Exporter\Source;

use PropelCollection;

/**
* Read data from a PropelCollection.
*
* @author Kévin Gomez <contact@kevingomez.fr>
*
* NEXT_MAJOR: Remove this class.
*
* @deprecated since exporter 2.x to be removed in 3.0.
*/
final class PropelCollectionSourceIterator extends AbstractPropertySourceIterator
{
Expand All @@ -32,6 +34,11 @@ final class PropelCollectionSourceIterator extends AbstractPropertySourceIterato
*/
public function __construct(\PropelCollection $collection, array $fields, string $dateTimeFormat = 'r')
{
@trigger_error(sprintf(
'The %s class is deprecated since sonata-project/exporter 2.x, to be removed in version 3.0.',
__CLASS__,
), \E_USER_DEPRECATED);

$this->collection = clone $collection;

parent::__construct($fields, $dateTimeFormat);
Expand Down
7 changes: 5 additions & 2 deletions src/Source/SymfonySitemapSourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ final class SymfonySitemapSourceIterator implements SourceIteratorInterface
private $routeName;

/**
* @var array
* @var array<string, mixed>
*/
private $parameters;

/**
* @param array<string, mixed> $parameters
*/
public function __construct(
\Iterator $source,
RouterInterface $router,
Expand All @@ -51,7 +54,7 @@ public function __construct(
}

/**
* @return array
* @return array<string, mixed>
*/
public function current()
{
Expand Down
12 changes: 1 addition & 11 deletions src/Writer/CsvWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function close(): void
public function write(array $data): void
{
if (0 === $this->position && $this->showHeaders) {
$this->addHeaders($data);
fputcsv($this->file, array_keys($data), $this->delimiter, $this->enclosure, $this->escape);

++$this->position;
}
Expand All @@ -147,14 +147,4 @@ public function write(array $data): void

++$this->position;
}

private function addHeaders(array $data): void
{
$headers = [];
foreach ($data as $header => $value) {
$headers[] = $header;
}

fputcsv($this->file, $headers, $this->delimiter, $this->enclosure, $this->escape);
}
}
4 changes: 2 additions & 2 deletions src/Writer/FormattedBoolWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public function close(): void
public function write(array $data): void
{
foreach ($data as $key => $value) {
if (\is_bool($data[$key])) {
$data[$key] = true === $data[$key] ? $this->trueLabel : $this->falseLabel;
if (\is_bool($value)) {
$data[$key] = true === $value ? $this->trueLabel : $this->falseLabel;
}
}
$this->writer->write($data);
Expand Down
4 changes: 2 additions & 2 deletions src/Writer/GsaFeedWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ private function generateNewPart(): void
++$this->bufferPart;

if (!$this->folder->isWritable()) {
throw new \RuntimeException(sprintf('Unable to write to folder: %s', $this->folder));
throw new \RuntimeException(sprintf('Unable to write to folder: %s', (string) $this->folder));
}

$this->buffer = fopen(sprintf('%s/feed_%05d.xml', $this->folder, $this->bufferPart), 'w');
$this->buffer = fopen(sprintf('%s/feed_%05d.xml', (string) $this->folder, $this->bufferPart), 'w');

$this->bufferSize += fwrite(
$this->buffer,
Expand Down
9 changes: 6 additions & 3 deletions src/Writer/InMemoryWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
final class InMemoryWriter implements WriterInterface
{
/**
* @var array
* @var array<mixed>
*/
private $elements;

Expand All @@ -25,16 +25,19 @@ public function open(): void
$this->elements = [];
}

public function close()
public function close(): void
{
return $this->elements;
unset($this->elements);
}

public function write(array $data): void
{
$this->elements[] = $data;
}

/**
* @return mixed[]
*/
public function getElements(): array
{
return $this->elements;
Expand Down
27 changes: 16 additions & 11 deletions src/Writer/SitemapWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ final class SitemapWriter implements WriterInterface
private $buffer;

/**
* @var array
* @var string[]
*/
private $headers;

Expand All @@ -69,10 +69,10 @@ final class SitemapWriter implements WriterInterface
private $bufferPart = 0;

/**
* @param string $folder The folder to store the sitemap.xml file
* @param mixed $groupName Name of sub-sitemap (optional)
* @param array $headers Indicate the need for namespace in the header sitemap
* @param bool $autoIndex If you want to generate index of sitemap (optional)
* @param string $folder The folder to store the sitemap.xml file
* @param mixed $groupName Name of sub-sitemap (optional)
* @param string[] $headers Indicate the need for namespace in the header sitemap
* @param bool $autoIndex If you want to generate index of sitemap (optional)
*/
public function __construct(string $folder, $groupName = false, array $headers = [], bool $autoIndex = true)
{
Expand Down Expand Up @@ -217,7 +217,9 @@ private function addSitemapLine(string $line): void
/**
* Build data with default parameters.
*
* @param array $data List of parameters
* @param array<string, mixed> $data List of parameters
*
* @return array<string, mixed>
*/
private function buildData(array $data): array
{
Expand All @@ -240,7 +242,7 @@ private function buildData(array $data): array
* Fix type of data, if data type is specific,
* he must to be defined in data and he must to be a array.
*
* @param array $data List of parameters
* @param array<string, mixed> $data List of parameters
*/
private function fixDataType(array &$data): void
{
Expand All @@ -253,15 +255,18 @@ private function fixDataType(array &$data): void
'video' => 'video',
];

if (!isset($valid_var_name[$data['type']], $data[$valid_var_name[$data['type']]]) || !\is_array($data[$valid_var_name[$data['type']]])) {
if (
!isset($valid_var_name[$data['type']], $data[$valid_var_name[$data['type']]])
|| !\is_array($data[$valid_var_name[$data['type']]])
) {
$data['type'] = 'default';
}
}

/**
* Generate standard line of sitemap.
*
* @param array $data List of parameters
* @param array<string, mixed> $data List of parameters
*/
private function generateDefaultLine(array $data): string
{
Expand All @@ -271,7 +276,7 @@ private function generateDefaultLine(array $data): string
/**
* Generate image line of sitemap.
*
* @param array $data List of parameters
* @param array<string, mixed> $data List of parameters
*/
private function generateImageLine(array $data): string
{
Expand Down Expand Up @@ -302,7 +307,7 @@ private function generateImageLine(array $data): string
/**
* Generate video line of sitemap.
*
* @param array $data List of parameters
* @param array<string, mixed> $data List of parameters
*/
private function generateVideoLine(array $data): string
{
Expand Down

0 comments on commit d220cf8

Please sign in to comment.