Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DevKit updates for 3.x branch #675

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"matthiasnoback/symfony-dependency-injection-test": "^4.0 || ^5.0",
"phpoffice/phpspreadsheet": "^1.23",
"phpstan/extension-installer": "^1.0",
"phpstan/phpdoc-parser": "^1.0",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0",
Expand Down
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use Rector\Config\RectorConfig;
use Rector\Php70\Rector\FunctionLike\ExceptionHandlerTypehintRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\NarrowUnusedSetUpDefinedPropertyRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;
Expand All @@ -40,5 +41,6 @@
$rectorConfig->skip([
ExceptionHandlerTypehintRector::class,
PreferPHPUnitThisCallRector::class,
NarrowUnusedSetUpDefinedPropertyRector::class,
]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private function configureWriters(ContainerBuilder $container, array $config): v
{
foreach ($config as $format => $settings) {
foreach ($settings as $key => $value) {
$container->setParameter(sprintf(
$container->setParameter(\sprintf(
'sonata.exporter.writer.%s.%s',
$format,
$key
Expand Down
4 changes: 2 additions & 2 deletions src/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(array $writers = [])
public function getResponse(string $format, string $filename, \Iterator $source): StreamedResponse
{
if (!\array_key_exists($format, $this->writers)) {
throw new \RuntimeException(sprintf(
throw new \RuntimeException(\sprintf(
'Invalid "%s" format, supported formats are : "%s"',
$format,
implode(', ', array_keys($this->writers))
Expand All @@ -58,7 +58,7 @@ public function getResponse(string $format, string $filename, \Iterator $source)
};

$headers = [
'Content-Disposition' => sprintf('attachment; filename="%s"', $filename),
'Content-Disposition' => \sprintf('attachment; filename="%s"', $filename),
];

$headers['Content-Type'] = $writer->getDefaultMimeType();
Expand Down
2 changes: 1 addition & 1 deletion src/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class Handler
{
public function __construct(
private \Iterator $source,
private WriterInterface $writer
private WriterInterface $writer,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Source/AbstractPropertySourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ abstract class AbstractPropertySourceIterator implements \Iterator
public function __construct(
protected array $fields,
protected string $dateTimeFormat = 'r',
protected bool $useBackedEnumValue = true
protected bool $useBackedEnumValue = true,
) {
$this->propertyAccessor = PropertyAccess::createPropertyAccessor();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Source/AbstractXmlSourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ abstract class AbstractXmlSourceIterator implements \Iterator

public function __construct(
protected string $filename,
protected bool $hasHeaders = true
protected bool $hasHeaders = true,
) {
}

Expand Down Expand Up @@ -111,7 +111,7 @@ final public function rewind(): void

$file = fopen($this->filename, 'r');
if (false === $file) {
throw new \Exception(sprintf('Cannot open file %s.', $this->filename));
throw new \Exception(\sprintf('Cannot open file %s.', $this->filename));
}
$this->file = $file;

Expand Down
4 changes: 2 additions & 2 deletions src/Source/CsvSourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct(
private string $delimiter = ',',
private string $enclosure = '"',
private string $escape = '\\',
private bool $hasHeaders = true
private bool $hasHeaders = true,
) {
}

Expand Down Expand Up @@ -86,7 +86,7 @@ public function rewind(): void
{
$file = fopen($this->filename, 'r');
if (false === $file) {
throw new \Exception(sprintf('Cannot open file %s.', $this->filename));
throw new \Exception(\sprintf('Cannot open file %s.', $this->filename));
}
$this->file = $file;

Expand Down
2 changes: 1 addition & 1 deletion src/Source/DoctrineDBALConnectionSourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ final class DoctrineDBALConnectionSourceIterator implements \Iterator
public function __construct(
private Connection $connection,
private string $query,
private array $parameters = []
private array $parameters = [],
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Source/DoctrineODMQuerySourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(
array $fields,
string $dateTimeFormat = \DateTimeInterface::ATOM,
private int $batchSize = 100,
bool $useBackedEnumValue = true
bool $useBackedEnumValue = true,
) {
$this->query = clone $query;

Expand Down
2 changes: 1 addition & 1 deletion src/Source/IteratorCallbackSourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class IteratorCallbackSourceIterator extends IteratorSourceIterator
*/
public function __construct(
\Iterator $iterator,
private \Closure $transformer
private \Closure $transformer,
) {
parent::__construct($iterator);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Source/SymfonySitemapSourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(
private \Iterator $source,
private RouterInterface $router,
private string $routeName,
private array $parameters = []
private array $parameters = [],
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Source/XmlSourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class XmlSourceIterator extends AbstractXmlSourceIterator
public function __construct(
string $filename,
private string $mainTag = 'datas',
private string $dataTag = 'data'
private string $dataTag = 'data',
) {
parent::__construct($filename, false);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Writer/CsvWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public function __construct(
private string $escape = '\\',
private bool $showHeaders = true,
private bool $withBom = false,
private string $terminate = "\n"
private string $terminate = "\n",
) {
$this->position = 0;

if (is_file($filename)) {
throw new \RuntimeException(sprintf('The file %s already exist', $filename));
throw new \RuntimeException(\sprintf('The file %s already exist', $filename));
}
}

Expand All @@ -63,7 +63,7 @@ public function open(): void
{
$file = fopen($this->filename, 'w', false);
if (false === $file) {
throw new \Exception(sprintf('Cannot open file %s.', $this->filename));
throw new \Exception(\sprintf('Cannot open file %s.', $this->filename));
}
$this->file = $file;

Expand Down
2 changes: 1 addition & 1 deletion src/Writer/FormattedBoolWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class FormattedBoolWriter implements WriterInterface
public function __construct(
private WriterInterface $writer,
private string $trueLabel = 'yes',
private string $falseLabel = 'no'
private string $falseLabel = 'no',
) {
}

Expand Down
14 changes: 7 additions & 7 deletions src/Writer/GsaFeedWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(
private \SplFileInfo $folder,
private string $dtd,
private string $datasource,
private string $feedtype
private string $feedtype,
) {
$this->bufferPart = 0;
$this->bufferSize = 0;
Expand All @@ -57,7 +57,7 @@ public function open(): void

public function write(array $data): void
{
$line = sprintf(
$line = \sprintf(
" <record url=\"%s\" mimetype=\"%s\" action=\"%s\"/>\n",
$data['url'],
$data['mime_type'],
Expand All @@ -71,7 +71,7 @@ public function write(array $data): void

$written = fwrite($this->getBuffer(), $line);
if (false === $written) {
throw new \Exception(sprintf('Cannot write line %s in the buffer.', $line));
throw new \Exception(\sprintf('Cannot write line %s in the buffer.', $line));
}

$this->bufferSize += $written;
Expand Down Expand Up @@ -99,13 +99,13 @@ private function generateNewPart(): void
++$this->bufferPart;

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

$filename = sprintf('%s/feed_%05d.xml', (string) $this->folder, $this->bufferPart);
$filename = \sprintf('%s/feed_%05d.xml', (string) $this->folder, $this->bufferPart);
$buffer = fopen($filename, 'w');
if (false === $buffer) {
throw new \Exception(sprintf('Cannot open file %s.', $filename));
throw new \Exception(\sprintf('Cannot open file %s.', $filename));
}
$this->buffer = $buffer;

Expand All @@ -125,7 +125,7 @@ private function generateNewPart(): void
XML
);
if (false === $written) {
throw new \Exception(sprintf('Cannot write file %s.', $filename));
throw new \Exception(\sprintf('Cannot write file %s.', $filename));
}

$this->bufferSize += $written;
Expand Down
4 changes: 2 additions & 2 deletions src/Writer/JsonWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class JsonWriter implements TypedWriterInterface
public function __construct(private string $filename)
{
if (is_file($filename)) {
throw new \RuntimeException(sprintf('The file %s already exist', $filename));
throw new \RuntimeException(\sprintf('The file %s already exist', $filename));
}
}

Expand All @@ -52,7 +52,7 @@ public function open(): void
{
$file = fopen($this->filename, 'w', false);
if (false === $file) {
throw new \Exception(sprintf('Cannot open file %s.', $this->filename));
throw new \Exception(\sprintf('Cannot open file %s.', $this->filename));
}

$this->file = $file;
Expand Down
30 changes: 15 additions & 15 deletions src/Writer/SitemapWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(
private string $folder,
private string $groupName = '',
private array $headers = [],
private bool $autoIndex = true
private bool $autoIndex = true,
) {
$this->pattern = 'sitemap_'.('' !== $this->groupName ? $this->groupName.'_' : '').'%05d.xml';
}
Expand Down Expand Up @@ -120,18 +120,18 @@ public function close(): void
public static function generateSitemapIndex(string $folder, string $baseUrl, string $pattern = 'sitemap*.xml', string $filename = 'sitemap.xml'): void
{
$content = "<?xml version='1.0' encoding='UTF-8'?>\n<sitemapindex xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.sitemaps.org/schemas/sitemap/1.0 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd' xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'>\n";
$files = glob(sprintf('%s/%s', $folder, $pattern));
$files = glob(\sprintf('%s/%s', $folder, $pattern));
if (false === $files) {
throw new \RuntimeException('Cannot find sitemap files.');
}

foreach ($files as $file) {
$stat = stat($file);
if (false === $stat) {
throw new \RuntimeException(sprintf('Cannot access to stats of the file %s.', $file));
throw new \RuntimeException(\sprintf('Cannot access to stats of the file %s.', $file));
}

$content .= sprintf(
$content .= \sprintf(
"\t".'<sitemap><loc>%s/%s</loc><lastmod>%s</lastmod></sitemap>'."\n",
$baseUrl,
basename($file),
Expand All @@ -141,7 +141,7 @@ public static function generateSitemapIndex(string $folder, string $baseUrl, str

$content .= '</sitemapindex>';

file_put_contents(sprintf('%s/%s', $folder, $filename), $content);
file_put_contents(\sprintf('%s/%s', $folder, $filename), $content);
}

/**
Expand All @@ -160,20 +160,20 @@ private function generateNewPart(): void
++$this->bufferPart;

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

$filename = sprintf($this->pattern, $this->bufferPart);
$filename = \sprintf($this->pattern, $this->bufferPart);

$buffer = fopen($this->folder.'/'.$filename, 'w');
if (false === $buffer) {
throw new \Exception(sprintf('Cannot open file %s.', $this->folder.'/'.$filename));
throw new \Exception(\sprintf('Cannot open file %s.', $this->folder.'/'.$filename));
}
$this->buffer = $buffer;

$written = fwrite($this->buffer, '<?xml version="1.0" encoding="UTF-8"?>'."\n".'<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"'.$this->getHeaderByFlag().'>'."\n");
if (false === $written) {
throw new \Exception(sprintf('Cannot write file %s.', $this->folder.'/'.$filename));
throw new \Exception(\sprintf('Cannot write file %s.', $this->folder.'/'.$filename));
}

$this->bufferSize += $written;
Expand All @@ -196,7 +196,7 @@ private function addSitemapLine(string $line): void

$written = fwrite($this->getBuffer(), $line);
if (false === $written) {
throw new \Exception(sprintf('Cannot write line %s in the buffer.', $line));
throw new \Exception(\sprintf('Cannot write line %s in the buffer.', $line));
}

$this->bufferSize += $written;
Expand Down Expand Up @@ -258,7 +258,7 @@ private function fixDataType(array &$data): void
*/
private function generateDefaultLine(array $data): string
{
return sprintf(
return \sprintf(
' <url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%s</priority></url>'."\n",
$data['url'],
(new \DateTime($data['lastmod']))->format('Y-m-d'),
Expand Down Expand Up @@ -289,13 +289,13 @@ private function generateImageLine(array $data): string
$images .= '<image:image>';

foreach ($image as $key => $element) {
$images .= sprintf('<image:%1$s>%2$s</image:%1$s>', $builder[$key] ?? $key, $element);
$images .= \sprintf('<image:%1$s>%2$s</image:%1$s>', $builder[$key] ?? $key, $element);
}

$images .= '</image:image>';
}

return sprintf(' <url><loc>%s</loc>%s</url>'."\n", $data['url'], $images);
return \sprintf(' <url><loc>%s</loc>%s</url>'."\n", $data['url'], $images);
}

/**
Expand All @@ -311,10 +311,10 @@ private function generateVideoLine(array $data): string
];

foreach ($data['video'] as $key => $video) {
$videos .= sprintf('<video:%1$s>%2$s</video:%1$s>', $builder[$key] ?? $key, $video);
$videos .= \sprintf('<video:%1$s>%2$s</video:%1$s>', $builder[$key] ?? $key, $video);
}

return sprintf(' <url><loc>%s</loc><video:video>%s</video:video></url>'."\n", $data['url'], $videos);
return \sprintf(' <url><loc>%s</loc><video:video>%s</video:video></url>'."\n", $data['url'], $videos);
}

/**
Expand Down
Loading
Loading