Skip to content

Commit

Permalink
Remove Symfony 5.4 support and PHP 7.4, 8.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
hlecorche committed Nov 22, 2024
1 parent 69ba061 commit a794a8b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 83 deletions.
28 changes: 1 addition & 27 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,24 @@ jobs:
matrix:
include:
#Mini (for each Symfony version)
- php-version: '7.4'
symfony-version: '5.4.*'
composer-flags: '--prefer-stable --prefer-lowest'
install-dos2unix: true
description: 'with SF 5.4.* lowest'
- php-version: '8.1'
symfony-version: '6.4.*'
composer-flags: '--prefer-stable --prefer-lowest'
install-dos2unix: true
description: 'with SF 6.4.* lowest'
- php-version: '8.2'
symfony-version: '7.0.*'
composer-flags: '--prefer-stable --prefer-lowest'
install-dos2unix: true
description: 'with SF 7.0.* lowest'
- php-version: '8.2'
symfony-version: '7.1.*'
composer-flags: '--prefer-stable --prefer-lowest'
install-dos2unix: true
description: 'with SF 7.1.* lowest'

#Symfony versions
- php-version: '8.3'
symfony-version: '5.4.*'
description: 'with SF 5.4.*'
- php-version: '8.3'
symfony-version: '5.4.*@dev'
description: 'with SF 5.4.* dev'
- php-version: '8.3'
symfony-version: '6.4.*'
description: 'with SF 6.4.*'
- php-version: '8.3'
symfony-version: '6.4.*@dev'
description: 'with SF 6.4.* dev'
- php-version: '8.3'
symfony-version: '7.0.*'
description: 'with SF 7.0.*'
- php-version: '8.3'
symfony-version: '7.0.*@dev'
description: 'with SF 7.0.* dev'
- php-version: '8.3'
symfony-version: '7.1.*'
description: 'with SF 7.1.*'
Expand All @@ -65,10 +43,6 @@ jobs:
description: 'with SF 7.2.* dev'

#PHP versions
- php-version: '7.4'
install-dos2unix: true
- php-version: '8.0'
install-dos2unix: true
- php-version: '8.1'
- php-version: '8.2'
- php-version: '8.3'
Expand All @@ -80,7 +54,7 @@ jobs:
coding-standards: true

#Static Analysis (min PHP version)
- php-version: '7.4'
- php-version: '8.1'
description: 'with Static Analysis'
static-analysis: true

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"psr-4": { "Ecommit\\CsvTableGenerator\\Tests\\": "tests/" }
},
"require": {
"php": "^7.4|^8.0",
"symfony/options-resolver": "^5.4|^6.4|^7.0"
"php": "^8.1",
"symfony/options-resolver": "^6.4|^7.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
Expand Down
8 changes: 8 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>

<issueHandlers>
<DeprecatedProperty>
<errorLevel type="suppress">
<file name="src/Csv.php" />
</errorLevel>
</DeprecatedProperty>
</issueHandlers>
</psalm>
31 changes: 9 additions & 22 deletions src/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,15 @@ class Csv

/**
* @var bool
*
* @deprecated No longer used
*/
protected $unixToDos = false;

/**
* @var string
*
* @deprecated No longer used
*/
protected $unixToDosPath;

Expand Down Expand Up @@ -130,6 +134,7 @@ public function __construct(string $pathDir, string $filename, array $options =
$resolver->setAllowedTypes('escape', 'string');
$resolver->setAllowedTypes('unix2dos_path', 'string');
$resolver->setAllowedTypes('add_utf8_bom', 'bool');
$resolver->setDeprecated('unix2dos_path', 'ecommit/csv-table-generator', '1.3');
$this->configureOptions($resolver);
$options = $resolver->resolve($options);

Expand All @@ -152,9 +157,7 @@ public function __construct(string $pathDir, string $filename, array $options =
$this->eol = $options['eol'];
$this->escape = $options['escape'];

if (self::EOL_CRLF === $options['eol'] && \PHP_VERSION_ID < 80100) { // PHP < 8.1
$this->unixToDos = true;
}
/* @psalm-suppress DeprecatedProperty */
$this->unixToDosPath = $options['unix2dos_path'];

$this->addUtf8Bom = $options['add_utf8_bom'];
Expand Down Expand Up @@ -201,18 +204,6 @@ public function close(): void
if (\is_resource($this->handle)) {
fclose($this->handle);
$this->handle = null;

if ($this->unixToDos) { // PHP < 8.1
if (\PHP_OS_FAMILY === 'Linux') {
$command = \sprintf('%s %s 2> /dev/null', $this->unixToDosPath, $this->currentPathname);
} else {
$command = \sprintf('%s %s', $this->unixToDosPath, $this->currentPathname);
}
exec($command, $output, $returnVar);
if (0 !== $returnVar) {
throw new \Exception(\sprintf('Unix2dos error (%s file)', $this->filename));
}
}
}
}

Expand Down Expand Up @@ -242,13 +233,9 @@ public function write($data): void
}

// Write
if (\PHP_VERSION_ID >= 80100) { // PHP >= 8.1
$eol = (self::EOL_CRLF === $this->eol) ? "\r\n" : "\n";
/** @psalm-suppress TooManyArguments */
$result = fputcsv($this->handle, $data, $this->delimiter, $this->enclosure, $this->escape, $eol);
} else { // PHP < 8.1
$result = fputcsv($this->handle, $data, $this->delimiter, $this->enclosure, $this->escape);
}
$eol = (self::EOL_CRLF === $this->eol) ? "\r\n" : "\n";
/** @psalm-suppress TooManyArguments */
$result = fputcsv($this->handle, $data, $this->delimiter, $this->enclosure, $this->escape, $eol);
if (false === $result) {
throw new \Exception(\sprintf('Error during the writing in %s file', $this->filename));
}
Expand Down
32 changes: 0 additions & 32 deletions tests/CsvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,11 @@ class CsvTest extends TestCase
{
protected $path;

protected $unix2dosLocation = 'not-found';

protected function setUp(): void
{
$this->path = sys_get_temp_dir().'/test-csv';
$this->deleteDir();
mkdir($this->path);

if (\PHP_VERSION_ID < 80100) { // PHP < 8.1
$this->unix2dosLocation = exec('which unix2dos');
if (empty($this->unix2dosLocation)) {
throw new \Exception('unix2dos not found');
}
}
}

protected function tearDown(): void
Expand Down Expand Up @@ -183,34 +174,11 @@ public function testWithEolOption(): void
{
$csv = $this->createCsv([
'eol' => Csv::EOL_CRLF,
'unix2dos_path' => $this->unix2dosLocation,
]);
$csv->write(['a a', 'bb']);
$csv->write(['cc', 'dd']);
$csv->close();

$this->assertCsvFile('my-csv.csv', [
'"a a",bb',
'cc,dd',
], true);
}

public function testWithBadUnix2DosPath(): void
{
if (\PHP_VERSION_ID < 80100) { // PHP < 8.1
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Unix2dos error (my-csv file)');
}

$csv = $this->createCsv([
'eol' => Csv::EOL_CRLF,
'unix2dos_path' => 'unix2dosFake',
]);
$csv->write(['a a', 'bb']);
$csv->write(['cc', 'dd']);
$csv->close();

// PHP >= 8.1
$this->assertCsvFile('my-csv.csv', [
'"a a",bb',
'cc,dd',
Expand Down

0 comments on commit a794a8b

Please sign in to comment.