Skip to content

Commit

Permalink
Merge c1cfd32 into 022935a
Browse files Browse the repository at this point in the history
  • Loading branch information
noelma committed Dec 4, 2021
2 parents 022935a + c1cfd32 commit f0ffa18
Show file tree
Hide file tree
Showing 53 changed files with 4,163 additions and 2,660 deletions.
5 changes: 3 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
/tests export-ignore
.coveralls.yml export-ignore
.gitattributes export-ignore
.github export-ignore
.gitignore export-ignore
.php_cs.dist export-ignore
.php-cs-fixer.dist.php export-ignore
.travis.yml export-ignore
phpdoc.dist.xml export-ignore
phpunit.xml export-ignore
phpunit.xml.dist export-ignore
phpstan.neon.dist export-ignore
USAGE.md export-ignore
README_fr.md export-ignore
README_fr.md export-ignore
49 changes: 49 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Tests

on: [push, pull_request]

jobs:
tests:
name: Tests PHP ${{ matrix.php }}
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
php: [7.2, 7.3, 7.4, 8.0, 8.1]
experimental: [false]
include:
- php: 7.4
analysis: true

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug

- name: Install dependencies with Composer
uses: ramsey/composer-install@v1

- name: Coding standards
if: matrix.analysis
run: bin/php-cs-fixer fix --ansi --dry-run --using-cache=no --verbose

- name: Static analysis
if: matrix.analysis
run: bin/phpstan --memory-limit=1G analyse

- name: Unit tests
run: bin/phpunit --coverage-clover clover.xml

- name: Upload coverage results to Coveralls
if: matrix.analysis
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
composer require php-coveralls/php-coveralls -n -W
bin/php-coveralls --coverage_clover=clover.xml -v
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Repertory
/.scannerwork/
/bin/
/build/
/nbproject/
/vendor/
Expand All @@ -8,5 +9,4 @@
/*.lock
/*.phar
/*.properties
/.php_cs.cache
/.phpunit.result.cache
/*.cache
13 changes: 3 additions & 10 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
->exclude('build')
->in(__DIR__);

return PhpCsFixer\Config::create()
->setRules([
$config = new PhpCsFixer\Config();
return $config->setRules([
'@PSR2' => true,
/* Force la déclaration des tableaux sous leur forme courte. */
'array_syntax' => [ 'syntax' => 'short' ],
Expand All @@ -24,7 +24,6 @@
'concat_space' => [ 'spacing' => 'one' ],
/* Remplace les commentaires simples # par //. */
'fully_qualified_strict_types' => true,
'hash_to_slash_comment' => true,
/* Retire les parenthèses des include/require. */
'include' => true,
/* Ne pas avoir de code à l'ouverture d'une balise php */
Expand Down Expand Up @@ -55,22 +54,18 @@
'no_mixed_echo_print' => true,
/* Supprime les espaces d'une seule ligne avant la fermeture du point-virgule. */
'no_singleline_whitespace_before_semicolons' => true,
/* Supprimes les espaces autour des accolades des tableaux. */
'no_spaces_around_offset' => [ 'outside' ],
/* Remplace les éléments elseif superflus par if. */
'no_superfluous_elseif' => true,
/* Supprime les accolades superflus. */
'no_unneeded_curly_braces' => true,
/* Supprime les parenthèses superflus. */
'no_unneeded_control_parentheses' => true,
/* Une class final ne doit pas avoir de méthodes finales. */
'no_unneeded_final_method' => true,
/* Supprimez les virgules de fin dans les listes. */
'no_trailing_comma_in_list_call' => true,
/* Supprimez les virgules de fin dans les array. */
'no_trailing_comma_in_singleline_array' => true,
/* Remplace les <?= par des <?php echo. */
'no_short_echo_tag' => true,
'echo_tag_syntax' => true,
/* Les annotations PHPUnit doivent être un FQCN, y compris un espace de noms racine. */
'php_unit_fqcn_annotation' => true,
/* Appliquez la camelCase aux méthodes de test PHPUnit, après la configuration. */
Expand All @@ -83,8 +78,6 @@
'phpdoc_no_access' => true,
/* Ordonne les annotations PHPDoc. */
'phpdoc_order' => true,
/* Les docblocks ne doivent être utilisés que sur des éléments structurels. */
'phpdoc_to_comment' => true,
/* Supprime les lignes vides au début et fin de la PHPDoc. */
'phpdoc_trim' => true,
/* Les variables locales, dynamiques et directement référencées ne doivent pas être affectées ni directement renvoyées par une fonction ou une méthode. */
Expand Down
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Queryflatfile

[![Build Status](https://travis-ci.org/soosyze/queryflatfile.svg?branch=master)](https://travis-ci.org/soosyze/queryflatfile "Travis")
[![Build Status](https://github.com/soosyze/queryflatfile/workflows/Tests/badge.svg?branch=master)](https://github.com/soosyze/queryflatfile/actions?query=branch:master "Tests")
[![Coverage Status](https://coveralls.io/repos/github/soosyze/queryflatfile/badge.svg?branch=master)](https://coveralls.io/github/soosyze/queryflatfile?branch=master "Coveralls")
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/soosyze/queryflatfile/blob/master/LICENSE "LICENSE")
[![Packagist](https://img.shields.io/packagist/v/soosyze/queryflatfile.svg)](https://packagist.org/packages/soosyze/queryflatfile "Packagist")
Expand Down
2 changes: 1 addition & 1 deletion README_fr.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Queryflatfile

[![Build Status](https://travis-ci.org/soosyze/queryflatfile.svg?branch=master)](https://travis-ci.org/soosyze/queryflatfile "Travis")
[![Build Status](https://github.com/soosyze/queryflatfile/workflows/Tests/badge.svg?branch=master)](https://github.com/soosyze/queryflatfile/actions?query=branch:master "Tests")
[![Coverage Status](https://coveralls.io/repos/github/soosyze/queryflatfile/badge.svg?branch=master)](https://coveralls.io/github/soosyze/queryflatfile?branch=master "Coveralls")
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/soosyze/queryflatfile/blob/master/LICENSE "LICENSE")
[![Packagist](https://img.shields.io/packagist/v/soosyze/queryflatfile.svg)](https://packagist.org/packages/soosyze/queryflatfile "Packagist")
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
"php": ">=7.2"
},
"require-dev": {
"phpstan/phpstan": "^0.12.85",
"phpstan/phpstan-phpunit": "^0.12.18",
"friendsofphp/php-cs-fixer": "^3.2",
"phpstan/phpstan": "^1.1",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^8.5"
},
"suggest": {
"friendsofphp/php-cs-fixer": "To normalize the PHP code.",
"phpdocumentor/phpdocumentor": "To generate documentation.",
"phpmetrics/phpmetrics": "To generate a code status report in HTML format."
},
Expand All @@ -34,10 +34,11 @@
},
"autoload-dev": {
"psr-4": {
"Queryflatfile\\Test\\": "tests"
"Queryflatfile\\Tests\\": "tests"
}
},
"config": {
"bin-dir": "bin",
"sort-packages": true,
"optimize-autoloader": true
}
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ parameters:
- src
- tests
tmpDir: build/phpStan
checkMissingIterableValueType: false
checkMissingIterableValueType: false
10 changes: 5 additions & 5 deletions src/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function create(string $path, string $fileName, array $data = []): bool

$handle = fopen($file, 'w+');
if ($handle === false) {
throw new DriverException("$file file cannot be opened");
throw new DriverException(sprintf('The %s file cannot be opened', $file));
}
fwrite($handle, $this->serializeData($data));

Expand Down Expand Up @@ -108,7 +108,7 @@ public function save(string $path, string $fileName, array $data): bool

$handle = fopen($file, 'w');
if ($handle === false) {
throw new DriverException("$file file cannot be opened");
throw new DriverException(sprintf('The %s file cannot be opened', $file));
}
fwrite($handle, $this->serializeData($data));

Expand Down Expand Up @@ -158,7 +158,7 @@ public function getFile(string $path, string $fileName): string
protected function isExist(string $file): void
{
if (!file_exists($file)) {
throw new FileNotFoundException("The $file file is missing.");
throw new FileNotFoundException(sprintf('The %s file is missing.', $file));
}
}

Expand All @@ -176,7 +176,7 @@ protected function isExist(string $file): void
protected function isWrite(string $file): void
{
if (!\is_writable($file)) {
throw new FileNotWritableException("The $file file is not writable.");
throw new FileNotWritableException(sprintf('The %s file is not writable.', $file));
}
}

Expand All @@ -194,7 +194,7 @@ protected function isWrite(string $file): void
protected function isRead(string $file): void
{
if (!\is_readable($file)) {
throw new FileNotReadableException("The $file file is not readable.");
throw new FileNotReadableException(sprintf('The %s file is not readable.', $file));
}
}
}
14 changes: 12 additions & 2 deletions src/Driver/Igbinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,24 @@ public function getExtension(): string
*/
public function serializeData(array $data): string
{
return igbinary_serialize($data);
$serializeData = igbinary_serialize($data);
if (!is_string($serializeData)) {
throw new \Exception('An error occurred in serializing the data.');
}

return $serializeData;
}

/**
* {@inheritDoc}
*/
public function unserializeData(string $data): array
{
return igbinary_unserialize($data);
$dataUnserialize = igbinary_unserialize($data);
if (!is_array($dataUnserialize)) {
throw new \Exception('An error occurred in deserializing the data.');
}

return $dataUnserialize;
}
}
16 changes: 11 additions & 5 deletions src/Driver/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,24 @@ public function getExtension(): string
*/
public function serializeData(array $data): string
{
$encode = json_encode($data, JSON_UNESCAPED_UNICODE);
$serializeData = json_encode($data, JSON_UNESCAPED_UNICODE);
if (!is_string($serializeData)) {
throw new \Exception('An error occurred in serializing the data.');
}

return $encode === false
? '{}'
:$encode;
return $serializeData;
}

/**
* {@inheritDoc}
*/
public function unserializeData(string $data): array
{
return json_decode($data, true, 512, JSON_UNESCAPED_UNICODE);
$dataUnserialize = json_decode($data, true, 512, JSON_UNESCAPED_UNICODE);
if (!is_array($dataUnserialize)) {
throw new \Exception('An error occurred in deserializing the data.');
}

return $dataUnserialize;
}
}
7 changes: 6 additions & 1 deletion src/Driver/Txt.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public function serializeData(array $data): string
*/
public function unserializeData(string $data): array
{
return unserialize($data);
$dataUnserialize = unserialize($data);
if (!is_array($dataUnserialize)) {
throw new \Exception('An error occurred in deserializing the data.');
}

return $dataUnserialize;
}
}
7 changes: 7 additions & 0 deletions src/Exception/Driver/FileNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@
*/
class FileNotFoundException extends DriverException
{
public function __construct(
string $message = '',
int $code = 0,
\Throwable $previous = null
) {
parent::__construct(str_replace('\\', '/', $message), $code, $previous);
}
}
14 changes: 0 additions & 14 deletions src/Exception/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,4 @@
*/
class Exception extends \Exception
{
/**
* Les balises autorisées.
*
* @var string
*/
protected $balise = '<b><cite><code><em><i><span><sub><sup><strong><u>';

public function __construct(string $message = '', int $code = 0, \Throwable $previous = null)
{
$msgEntities = htmlentities($message, ENT_QUOTES, 'UTF-8');
$msgDecode = htmlspecialchars_decode($msgEntities);
$msgTags = strip_tags($msgDecode, $this->balise);
parent::__construct($msgTags, $code, $previous);
}
}
13 changes: 13 additions & 0 deletions src/Exception/Query/TableNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,17 @@
*/
class TableNotFoundException extends QueryException
{
public function __construct(
string $tableName = '',
int $code = 0,
\Throwable $previous = null
) {
parent::__construct(
$tableName === ''
? 'Table is missing.'
: sprintf('The %s table is missing.', $tableName),
$code,
$previous
);
}
}
Loading

0 comments on commit f0ffa18

Please sign in to comment.