Skip to content

Commit e235697

Browse files
committed
Adding PSR2 with PHP Coding Standards Fixer
1 parent 0cbf6a6 commit e235697

27 files changed

+816
-931
lines changed

.php_cs.dist

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
$finder = PhpCsFixer\Finder::create()
3+
->in(__DIR__);
4+
return PhpCsFixer\Config::create()
5+
->setRules([
6+
'@PSR2' => true,
7+
/* Force la déclaration des tableaux sous leur forme courte. */
8+
'array_syntax'=> ['syntax' => 'short'],
9+
/* Ajoute un saut de ligne avant chaque return en fin de fonction. */
10+
'blank_line_before_statement'=>true,
11+
/* Combine les isset() && successives. */
12+
'combine_consecutive_issets' => true,
13+
/* Combine les unset() successives. */
14+
'combine_consecutive_unsets'=>true,
15+
/* Remplace les commentaires simples # par //. */
16+
'hash_to_slash_comment'=>true,
17+
/* Retire les parenthèses des include/require. */
18+
'include'=>true,
19+
/* Ne pas avoir de code à l'ouverture d'une balise php */
20+
'linebreak_after_opening_tag'=>true,
21+
/* Supprime les commentaires vides. */
22+
'no_empty_comment'=>true,
23+
/* Supprime les blocks PHPDoc vides. */
24+
'no_empty_phpdoc'=>true,
25+
/* Supprimez les instructions de point virgule inutiles. */
26+
'no_empty_statement'=>true,
27+
/* Supprime les lignes vides supplémentaire. */
28+
'no_extra_blank_lines'=>true,
29+
/* La ligne de déclaration de l'espace de noms ne doit pas contenir d'espaces de début. */
30+
'no_leading_namespace_whitespace'=>true,
31+
/* Remplace les <?= par des <?php echo. */
32+
'no_short_echo_tag'=>true,
33+
/* Ordonne les éléments des class. */
34+
'ordered_class_elements'=>true
35+
])
36+
->setFinder($finder);

src/Driver.php

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
* Queryflatfile
5-
*
5+
*
66
* @package Queryflatfile
77
* @author Mathieu NOËL <[email protected]>
88
* @license https://github.com/soosyze/queryflatfile/blob/master/LICENSE (MIT License)
@@ -12,7 +12,7 @@
1212

1313
/**
1414
* Implementation partiel Queryflatfile\DriverInterface.
15-
*
15+
*
1616
* @author Mathieu NOËL
1717
*/
1818
abstract class Driver implements DriverInterface
@@ -21,96 +21,94 @@ abstract class Driver implements DriverInterface
2121
/**
2222
* {@inheritDoc}
2323
*/
24-
abstract function create( $path, $fileName, array $data = [] );
24+
abstract public function create($path, $fileName, array $data = []);
2525

2626
/**
2727
* {@inheritDoc}
2828
*/
29-
abstract function read( $path, $fileName );
29+
abstract public function read($path, $fileName);
3030

3131
/**
3232
* {@inheritDoc}
3333
*/
34-
abstract function save( $path, $fileName, array $data );
34+
abstract public function save($path, $fileName, array $data);
3535

3636
/**
3737
* {@inheritDoc}
3838
*/
39-
public function delete( $path, $fileName )
39+
public function delete($path, $fileName)
4040
{
4141
return unlink($this->getFile($path, $fileName));
4242
}
4343

4444
/**
4545
* {@inheritDoc}
4646
*/
47-
public function has( $path, $fileName )
47+
public function has($path, $fileName)
4848
{
4949
return file_exists($this->getFile($path, $fileName));
5050
}
5151

5252
/**
5353
* {@inheritDoc}
5454
*/
55-
abstract function getExtension();
55+
abstract public function getExtension();
5656

5757
/**
5858
* Concatène le chemin, le nom du fichier et l'extension.
59-
*
59+
*
6060
* @param string $path Chemin de la table.
6161
* @param string $fileName Nom du fichier.
62-
*
62+
*
6363
* @return string Chemin complet du fichier.
6464
*/
65-
public function getFile( $path, $fileName )
65+
public function getFile($path, $fileName)
6666
{
6767
$DS = DIRECTORY_SEPARATOR;
6868
$file = $path . $DS . $fileName . '.' . $this->getExtension();
69+
6970
return str_replace('\\', $DS, $file);
7071
}
7172

7273
/**
7374
* Déclenche une exception si le fichier passé en paramètre d'existe pas.
74-
*
75+
*
7576
* @param string $file Chemin complet du fichier.
76-
*
77+
*
7778
* @throws Exception\Driver\FileNotFoundException
7879
*/
79-
protected function isExist( $file )
80+
protected function isExist($file)
8081
{
81-
if( !file_exists($file) )
82-
{
82+
if (!file_exists($file)) {
8383
throw new Exception\Driver\FileNotFoundException('The ' . htmlspecialchars($file) . ' file is missing.');
8484
}
8585
}
8686

8787
/**
8888
* Déclenche une exception si le fichier passé en paramètre n'a pas le droit d'écriture.
89-
*
89+
*
9090
* @param string $file Chemin complet du fichier.
91-
*
91+
*
9292
* @throws Exception\Driver\FileNotWritableException
9393
*/
94-
protected function isWrite( $file )
94+
protected function isWrite($file)
9595
{
96-
if( !is_writable($file) )
97-
{
96+
if (!is_writable($file)) {
9897
throw new Exception\Driver\FileNotWritableException('The ' . htmlspecialchars($file) . ' file is not writable.');
9998
}
10099
}
101100

102101
/**
103102
* Déclenche une exception si le fichier passé en paramètre n'a pas le droit d'être lu.
104-
*
103+
*
105104
* @param string $file Chemin complet du fichier.
106-
*
105+
*
107106
* @throws Exception\Driver\FileNotReadableException
108107
*/
109-
protected function isRead( $file )
108+
protected function isRead($file)
110109
{
111-
if( !is_readable($file) )
112-
{
110+
if (!is_readable($file)) {
113111
throw new Exception\Driver\FileNotReadableException('The ' . htmlspecialchars($file) . ' file is not readable.');
114112
}
115113
}
116-
}
114+
}

src/DriverInterface.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
* Queryflatfile
5-
*
5+
*
66
* @package Queryflatfile
77
* @author Mathieu NOËL <[email protected]>
88
* @license https://github.com/soosyze/queryflatfile/blob/master/LICENSE (MIT License)
@@ -12,7 +12,7 @@
1212

1313
/**
1414
* Interface de manipulation de fichier de données.
15-
*
15+
*
1616
* @author Mathieu NOËL
1717
*/
1818
interface DriverInterface
@@ -21,73 +21,73 @@ interface DriverInterface
2121
/**
2222
* Créer un fichier si celui-ci n'existe pas et enregistre des données
2323
* Les données DOIVENT conserver leur type.
24-
*
24+
*
2525
* @param string $path Chemin du fichier.
2626
* @param string $fileName Nom du fichier SANS l'extension.
2727
* @param array $data Tableau associatif à enregistrer.
28-
*
28+
*
2929
* @throws Exception\Driver\ExtensionNotLoadedException Si l'extension n'est pas chargée.
30-
*
30+
*
3131
* @return bool TRUE si tous ce passe bien sinon FALSE.
3232
*/
33-
public function create( $path, $fileName, array $data = [] );
33+
public function create($path, $fileName, array $data = []);
3434

3535
/**
36-
* Lit un fichier et DOIT retourner son contenu sous forme de tableau associatif
36+
* Lit un fichier et DOIT retourner son contenu sous forme de tableau associatif
3737
* quelle que soit sa profondeur. Les données DOIVENT conserver leur type.
38-
*
38+
*
3939
* @param string $path Chemin du fichier.
4040
* @param string $fileName Nom du fichier SANS l'extension.
41-
*
41+
*
4242
* @throws Exception\Driver\ExtensionNotLoadedException Si l'extension n'est pas chargée.
4343
* @throws Exception\Driver\FileNotFoundException Si le fichier est introuvable.
4444
* @throws Exception\Driver\FileNotReadableException Si le fichier n'a pas les droits suffisant pour être lu.
45-
*
45+
*
4646
* @return array les données du fichier
4747
*/
48-
public function read( $path, $fileName );
48+
public function read($path, $fileName);
4949

5050
/**
5151
* Enregistre des données dans le fichier.
5252
* Les données DOIVENT conserver leur type.
53-
*
53+
*
5454
* @param string $path Chemin du fichier.
5555
* @param string $fileName Nom du fichier SANS l'extension.
5656
* @param array $data Tableau associatif à enregistrer.
57-
*
57+
*
5858
* @throws Exception\Driver\ExtensionNotLoadedException Si l'extension n'est pas chargée.
5959
* @throws Exception\Driver\FileNotFoundException Si le fichier est introuvable.
6060
* @throws Exception\Driver\FileNotWritableException Si le fichier n'a pas les droits suffisant pour être écrit.
61-
*
61+
*
6262
* @return bool TRUE si tous ce passe bien sinon FALSE.
6363
*/
64-
public function save( $path, $fileName, array $data );
64+
public function save($path, $fileName, array $data);
6565

6666
/**
6767
* Supprime un fichier.
68-
*
68+
*
6969
* @param string $path Chemin du fichier.
7070
* @param string $fileName Nom du fichier SANS l'extension.
71-
*
71+
*
7272
* @return bool TRUE si tous ce passe bien sinon FALSE.
7373
*/
74-
public function delete( $path, $fileName );
74+
public function delete($path, $fileName);
7575

7676
/**
7777
* Si le fichier existe.
78-
*
78+
*
7979
* @param string $path Chemin du fichier.
8080
* @param string $fileName Nom du fichier SANS l'extension.
81-
*
81+
*
8282
* @return bool
8383
*/
84-
public function has( $path, $fileName );
84+
public function has($path, $fileName);
8585

8686
/**
8787
* Renseigne le nom de l'extension de fichier utilisé par le driver
8888
* au reste des composant.
89-
*
89+
*
9090
* @return string Nom de l'extension SANS le point en préfix.
9191
*/
9292
public function getExtension();
93-
}
93+
}

src/DriverJson.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
* Queryflatfile
5-
*
5+
*
66
* @package Queryflatfile
77
* @author Mathieu NOËL <[email protected]>
88
* @license https://github.com/soosyze/queryflatfile/blob/master/LICENSE (MIT License)
@@ -13,7 +13,7 @@
1313
/**
1414
* Implémentation de Queryflatfile\DriverInterface par l'héritage de Queryflatfile\Driver
1515
* Manipule des données dans des fichiers de type JSON
16-
*
16+
*
1717
* @author Mathieu NOËL
1818
*/
1919
class DriverJson extends Driver
@@ -22,20 +22,19 @@ class DriverJson extends Driver
2222
/**
2323
* {@inheritDoc}
2424
*/
25-
public function create( $path, $fileName, array $data = [] )
25+
public function create($path, $fileName, array $data = [])
2626
{
2727
$this->checkExtension();
2828

2929
$file = $this->getFile($path, $fileName);
3030

31-
if( !file_exists($path) )
32-
{
31+
if (!file_exists($path)) {
3332
mkdir($path, 0775);
3433
}
35-
if( !file_exists($file) )
36-
{
34+
if (!file_exists($file)) {
3735
$fichier = fopen($file, 'w+');
3836
fwrite($fichier, json_encode($data));
37+
3938
return fclose($fichier);
4039
}
4140

@@ -45,7 +44,7 @@ public function create( $path, $fileName, array $data = [] )
4544
/**
4645
* {@inheritDoc}
4746
*/
48-
public function read( $path, $fileName )
47+
public function read($path, $fileName)
4948
{
5049
$this->checkExtension();
5150
$file = $this->getFile($path, $fileName);
@@ -54,13 +53,14 @@ public function read( $path, $fileName )
5453
$this->isRead($file);
5554

5655
$json = file_get_contents($file);
56+
5757
return json_decode($json, true);
5858
}
5959

6060
/**
6161
* {@inheritDoc}
6262
*/
63-
public function save( $path, $fileName, array $data )
63+
public function save($path, $fileName, array $data)
6464
{
6565
$this->checkExtension();
6666

@@ -71,6 +71,7 @@ public function save( $path, $fileName, array $data )
7171

7272
$fp = fopen($file, 'w');
7373
fwrite($fp, json_encode($data));
74+
7475
return fclose($fp);
7576
}
7677

@@ -84,7 +85,7 @@ public function getExtension()
8485

8586
/**
8687
* Si l'extension du type de fichier est chargée.
87-
*
88+
*
8889
* @return boolean
8990
*/
9091
private function isExtensionLoaded()
@@ -94,14 +95,13 @@ private function isExtensionLoaded()
9495

9596
/**
9697
* Déclanche une exception si le l'extension du fichier n'est pas chargée.
97-
*
98+
*
9899
* @throws Exception\Driver\ExtensionNotLoadedException
99100
*/
100101
private function checkExtension()
101102
{
102-
if( !$this->isExtensionLoaded() )
103-
{
103+
if (!$this->isExtensionLoaded()) {
104104
throw new Exception\Driver\ExtensionNotLoadedException('The json extension is not loaded.');
105105
}
106106
}
107-
}
107+
}

0 commit comments

Comments
 (0)