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 Dec 28, 2021
2 parents a4d6e6f + 756e9c8 commit 5c1657b
Show file tree
Hide file tree
Showing 51 changed files with 228 additions and 99 deletions.
3 changes: 3 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ parameters:
- # Disallow VariableMethodCallRule and VariablePropertyFetchRule
message: '#^Variable (method call|property access)#'
path: .
- # https://github.com/phpstan/phpstan-strict-rules/issues/130
message: '#^Call to static method PHPUnit\\Framework\\Assert::.* will always evaluate to true\.$#'
path: tests/
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ includes:
- phpstan-baseline.neon

parameters:
level: 2
level: 5
paths:
- src
- tests
Expand Down
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="8" 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="5" 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
1 change: 1 addition & 0 deletions src/Bridge/Symfony/Bundle/SonataExporterBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
ForwardCompatibleSonataExporterBundle::class
), \E_USER_DEPRECATED);

// @phpstan-ignore-next-line
if (false) {
/**
* NEXT_MAJOR: remove this class.
Expand Down
12 changes: 5 additions & 7 deletions src/Source/AbstractPropertySourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct(array $fields, string $dateTimeFormat = 'r')
}

/**
* @return mixed
* @return array<string, mixed>
*/
#[\ReturnTypeWillChange]
public function current()
Expand Down Expand Up @@ -134,17 +134,15 @@ public function getDuration(\DateInterval $interval): string

/**
* @param object|mixed[] $current
*
* @return array<string, mixed>
*/
protected function getCurrentData($current): array
{
$data = [];
foreach ($this->fields as $key => $field) {
if (\is_string($field)) {
$name = \is_string($key) ? $key : $field;
$propertyPath = $field;
} else {
throw new \TypeError('Unsupported field type. Field should be a string.');
}
$name = \is_string($key) ? $key : $field;
$propertyPath = $field;

try {
$propertyValue = $this->propertyAccessor->getValue($current, new PropertyPath($propertyPath));
Expand Down
6 changes: 5 additions & 1 deletion src/Source/AbstractXmlSourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ abstract class AbstractXmlSourceIterator implements SourceIteratorInterface

/**
* @var resource|null
* @phpstan-var resource|null
* @psalm-var resource|closed-resource|null
*/
protected $file;

Expand All @@ -41,7 +43,7 @@ abstract class AbstractXmlSourceIterator implements SourceIteratorInterface
protected $columns = [];

/**
* @var resource|null
* @var \XMLParser|null
*/
protected $parser;

Expand Down Expand Up @@ -178,7 +180,9 @@ final protected function parseRow(): void
}

$this->currentRowEnded = false;

// read file until row is ended
// @phpstan-ignore-next-line: The currentRowEnded value is updated when parsing the data
while (!$this->currentRowEnded && !feof($this->file)) {
$data = fread($this->file, 1024);
xml_parse($this->parser, $data);
Expand Down
13 changes: 5 additions & 8 deletions src/Source/CsvSourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ final class CsvSourceIterator implements SourceIteratorInterface

/**
* @var resource|null
* @phpstan-var resource|null
* @psalm-var resource|closed-resource|null
*/
private $file;

Expand All @@ -50,11 +52,6 @@ final class CsvSourceIterator implements SourceIteratorInterface
*/
private $hasHeaders;

/**
* @var array
*/
private $lines = [];

/**
* @var array
*/
Expand All @@ -66,7 +63,7 @@ final class CsvSourceIterator implements SourceIteratorInterface
private $position = 0;

/**
* @var array
* @var array|false
*/
private $currentLine = [];

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

/**
* @return mixed
* @return array|false
*/
#[\ReturnTypeWillChange]
public function current()
Expand All @@ -94,7 +91,7 @@ public function current()
}

/**
* @return mixed
* @return int
*/
#[\ReturnTypeWillChange]
public function key()
Expand Down
30 changes: 23 additions & 7 deletions src/Source/DoctrineDBALConnectionSourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ final class DoctrineDBALConnectionSourceIterator implements SourceIteratorInterf
private $query;

/**
* @var array
* @var mixed[]
*/
private $parameters;

/**
* @var mixed
* @var array<string, mixed>|false
*/
private $current;

Expand All @@ -48,13 +48,20 @@ final class DoctrineDBALConnectionSourceIterator implements SourceIteratorInterf
*/
private $result;

/**
* @param mixed[] $parameters
*/
public function __construct(Connection $connection, string $query, array $parameters = [])
{
$this->connection = $connection;
$this->query = $query;
$this->parameters = $parameters;
}

/**
* @return array<string, mixed>|false
*/
#[\ReturnTypeWillChange]
public function current()
{
return $this->current;
Expand All @@ -66,6 +73,10 @@ public function next(): void
++$this->position;
}

/**
* @return int
*/
#[\ReturnTypeWillChange]
public function key()
{
return $this->position;
Expand All @@ -76,16 +87,21 @@ public function valid(): bool
return \is_array($this->current);
}

/**
* @psalm-suppress InvalidPropertyAssignmentValue
*/
public function rewind(): void
{
$statement = $this->connection->prepare($this->query);

// TODO: Keep only the if part when dropping support for Doctrine DBAL < 3.1
if (method_exists($statement, 'executeQuery')) {
$this->result = $statement->executeQuery($this->parameters);
} else {
$statement->execute($this->parameters);
$result = $statement->execute($this->parameters);

// TODO: Keep only the if part when dropping support for Doctrine DBAL < 3.1
// @phpstan-ignore-next-line
if ($result instanceof Result) {
$this->result = $result;
} else { // @phpstan-ignore-line
// @phpstan-ignore-next-line
$this->result = $statement;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Source/DoctrineODMQuerySourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(Query $query, array $fields, string $dateTimeFormat
}

/**
* @return mixed
* @return array<string, mixed>
*/
public function current()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Source/DoctrineORMQuerySourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct(Query $query, array $fields, string $dateTimeFormat
}

/**
* @return mixed
* @return array<string, mixed>
*/
public function current()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Source/PDOStatementSourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function next(): void
}

/**
* @return mixed
* @return int
*/
#[\ReturnTypeWillChange]
public function key()
Expand Down
4 changes: 2 additions & 2 deletions src/Source/SourceIteratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
/**
* NEXT_MAJOR: Remove this interface.
*
* @deprecated since 2.9 use \Iterator instead.
* @deprecated since sonata-project/exporter 2.9 use \Iterator instead.
*
* @phpstan-extends \Iterator<array<mixed>>
* @phpstan-extends \Iterator<mixed>
*/
interface SourceIteratorInterface extends \Iterator
{
Expand Down
3 changes: 3 additions & 0 deletions src/Source/SymfonySitemapSourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public function __construct(
$this->parameters = $parameters;
}

/**
* @return array
*/
public function current()
{
$data = $this->source->current();
Expand Down
6 changes: 6 additions & 0 deletions src/Test/AbstractTypedWriterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

/**
* @author Grégoire Paris <postmaster@greg0ire.fr>
*
* NEXT_MAJOR: Remove this class.
*
* @deprecated since sonata-project/exporter 2.x, to be removed in version 3.0.
*/
abstract class AbstractTypedWriterTestCase extends TestCase
{
Expand All @@ -33,11 +37,13 @@ protected function setUp(): void

final public function testFormatIsString(): void
{
// @phpstan-ignore-next-line
static::assertIsString($this->writer->getFormat());
}

final public function testDefaultMimeTypeIsString(): void
{
// @phpstan-ignore-next-line
static::assertIsString($this->writer->getDefaultMimeType());
}

Expand Down
4 changes: 3 additions & 1 deletion src/Writer/CsvWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ final class CsvWriter implements TypedWriterInterface
private $escape;

/**
* @var resource
* @var resource|null
* @phpstan-var resource|null
* @psalm-var resource|closed-resource|null
*/
private $file;

Expand Down
2 changes: 2 additions & 0 deletions src/Writer/GsaFeedWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ final class GsaFeedWriter implements WriterInterface

/**
* @var resource|null
* @phpstan-var resource|null
* @psalm-var resource|closed-resource|null
*/
private $buffer;

Expand Down
4 changes: 3 additions & 1 deletion src/Writer/JsonWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ final class JsonWriter implements TypedWriterInterface
private $filename;

/**
* @var resource
* @var resource|null
* @phpstan-var resource|null
* @psalm-var resource|closed-resource|null
*/
private $file;

Expand Down
2 changes: 2 additions & 0 deletions src/Writer/SitemapWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ final class SitemapWriter implements WriterInterface

/**
* @var resource|null
* @phpstan-var resource|null
* @psalm-var resource|closed-resource|null
*/
private $buffer;

Expand Down
4 changes: 3 additions & 1 deletion src/Writer/XlsWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ final class XlsWriter implements TypedWriterInterface
private $filename;

/**
* @var resource
* @var resource|null
* @phpstan-var resource|null
* @psalm-var resource|closed-resource|null
*/
private $file;

Expand Down
2 changes: 2 additions & 0 deletions src/Writer/XmlExcelWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ final class XmlExcelWriter implements WriterInterface

/**
* @var resource|null
* @phpstan-var resource|null
* @psalm-var resource|closed-resource|null
*/
private $file;

Expand Down
9 changes: 3 additions & 6 deletions src/Writer/XmlWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@ final class XmlWriter implements TypedWriterInterface
private $filename;

/**
* @var resource
* @var resource|null
* @phpstan-var resource|null
* @psalm-var resource|closed-resource|null
*/
private $file;

/**
* @var int
*/
private $position = 0;

/**
* @var string
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use PHPUnit\Framework\TestCase;
use Sonata\Exporter\Bridge\Symfony\DependencyInjection\Configuration;

class ConfigurationTest extends TestCase
final class ConfigurationTest extends TestCase
{
use ConfigurationTestCaseTrait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class ExporterCompilerPassTest extends AbstractCompilerPassTestCase
final class ExporterCompilerPassTest extends AbstractCompilerPassTestCase
{
public function testWritersAreAddedToTheExporter(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
use Sonata\Exporter\Bridge\Symfony\DependencyInjection\SonataExporterExtension;

class SonataExporterExtensionTest extends AbstractExtensionTestCase
final class SonataExporterExtensionTest extends AbstractExtensionTestCase
{
public function testExporterServiceIsPresent(): void
{
Expand Down

0 comments on commit 5c1657b

Please sign in to comment.