Skip to content
This repository was archived by the owner on Nov 26, 2022. It is now read-only.

Commit 1de43cb

Browse files
author
Daniel Opitz
committed
Reformat code
1 parent a406340 commit 1de43cb

22 files changed

Lines changed: 342 additions & 200 deletions

.cs.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
return PhpCsFixer\Config::create()
4+
->setUsingCache(false)
5+
->setRiskyAllowed(true)
6+
//->setCacheFile(__DIR__ . '/.php_cs.cache')
7+
->setRules([
8+
'@PSR1' => true,
9+
'@PSR2' => true,
10+
'@Symfony' => true,
11+
'psr4' => true,
12+
// custom rules
13+
'align_multiline_comment' => true, // psr-5
14+
'array_indentation' => true,
15+
'array_syntax' => ['syntax' => 'short'],
16+
'cast_spaces' => ['space' => 'none'],
17+
'concat_space' => ['spacing' => 'one'],
18+
'compact_nullable_typehint' => true,
19+
'declare_equal_normalize' => ['space' => 'single'],
20+
'general_phpdoc_annotation_remove' => [
21+
'annotations' => [
22+
'author',
23+
'package',
24+
],
25+
],
26+
'increment_style' => ['style' => 'post'],
27+
'list_syntax' => ['syntax' => 'short'],
28+
'no_short_echo_tag' => true,
29+
'phpdoc_add_missing_param_annotation' => ['only_untyped' => false],
30+
'phpdoc_align' => false,
31+
'phpdoc_no_empty_return' => false,
32+
'phpdoc_order' => true, // psr-5
33+
'protected_to_private' => false,
34+
'yoda_style' => false,
35+
])
36+
->setFinder(PhpCsFixer\Finder::create()
37+
->in(__DIR__ . '/src')
38+
->in(__DIR__ . '/tests')
39+
->name('*.php')
40+
->ignoreDotFiles(true)
41+
->ignoreVCS(true));

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: php
22

33
php:
4-
- 7.0
54
- 7.1
65
- 7.2
76

@@ -21,8 +20,9 @@ before_script:
2120
- cd $TRAVIS_BUILD_DIR
2221

2322
script:
23+
- ant check-style
2424
- ant phpstan
25-
- vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
25+
- ant phpunit-coverage
2626

2727
#after_success:
2828
# - if [ "$TRAVIS_PHP_VERSION" == "7.1" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi

build.xml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,19 @@
2727

2828
<target name="fix-style" description="Code style fixer">
2929
<mkdir dir="${basedir}/build"/>
30-
<get src="https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.10.2/php-cs-fixer.phar" dest="${basedir}/build/php-cs-fixer.phar" skipexisting="true"/>
31-
<exec executable="php" searchpath="true" resolveexecutable="true">
30+
<get src="http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar" dest="${basedir}/build/php-cs-fixer.phar" skipexisting="true"/>
31+
<exec executable="php" searchpath="true" resolveexecutable="true" failonerror="true">
3232
<arg value="${basedir}/build/php-cs-fixer.phar"/>
33-
<arg value="fix"/>
34-
<arg value="--rules=@PSR2"/>
35-
<arg value="--using-cache=no"/>
36-
<arg path="${basedir}/src"/>
33+
<arg line="fix --config=.cs.php"/>
3734
</exec>
38-
<exec executable="php" searchpath="true" resolveexecutable="true">
35+
</target>
36+
37+
<target name="check-style" description="Code style check">
38+
<mkdir dir="${basedir}/build"/>
39+
<get src="http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar" dest="${basedir}/build/php-cs-fixer.phar" skipexisting="true"/>
40+
<exec executable="php" searchpath="true" resolveexecutable="true" failonerror="true">
3941
<arg value="${basedir}/build/php-cs-fixer.phar"/>
40-
<arg value="fix"/>
41-
<arg value="--rules=@PSR2"/>
42-
<arg value="--using-cache=no"/>
43-
<arg path="${basedir}/tests"/>
42+
<arg line="fix --dry-run --format=txt --verbose --diff --diff-format=udiff --config=.cs.php"/>
4443
</exec>
4544
</target>
4645

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
"require-dev": {
1515
"phpunit/phpunit": "^6.0"
1616
},
17+
"require": {
18+
"php": ">=7.1"
19+
},
1720
"scripts": {
1821
"test": "phpunit",
1922
"test-coverage": "phpunit --coverage-clover build/logs/clover.xml --coverage-html build/coverage",
@@ -22,12 +25,12 @@
2225
},
2326
"autoload": {
2427
"psr-4": {
25-
"Odan\\": "src"
28+
"Odan\\Database\\": "src/Database"
2629
}
2730
},
2831
"autoload-dev": {
2932
"psr-4": {
30-
"Odan\\Test\\": "tests"
33+
"Odan\\Database\\Test\\": "tests/"
3134
}
3235
},
3336
"config": {

src/Database/Compression.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
namespace Odan\Database;
44

55
/**
6-
* Class Compression
6+
* Class Compression.
77
*/
88
class Compression
99
{
10-
1110
/** @var Connection */
1211
protected $db = null;
1312

@@ -22,9 +21,10 @@ public function __construct(Connection $db)
2221
}
2322

2423
/**
25-
* Compress compatible with MySQL COMPRESS
24+
* Compress compatible with MySQL COMPRESS.
2625
*
2726
* @param string|mixed $value data to compress
27+
*
2828
* @return string|null compressed data
2929
*/
3030
public function compress($value)
@@ -37,9 +37,10 @@ public function compress($value)
3737
}
3838

3939
/**
40-
* Uncompress compatible with MySQL UNCOMPRESS
40+
* Uncompress compatible with MySQL UNCOMPRESS.
4141
*
4242
* @param string|mixed $value
43+
*
4344
* @return string|null
4445
*/
4546
public function uncompress($value)

src/Database/Condition.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
class Condition
88
{
9-
109
/**
11-
* PDO Connection
10+
* PDO Connection.
1211
*
1312
* @var Connection
1413
*/
@@ -20,21 +19,21 @@ class Condition
2019
protected $quoter;
2120

2221
/**
23-
* PDO Connection
22+
* PDO Connection.
2423
*
2524
* @var QueryInterface
2625
*/
2726
protected $query;
2827

2928
/**
30-
* Where clause
29+
* Where clause.
3130
*
3231
* @var array
3332
*/
3433
protected $where = [];
3534

3635
/**
37-
* Having clause
36+
* Having clause.
3837
*
3938
* @var array
4039
*/
@@ -57,6 +56,7 @@ public function __construct(Connection $pdo, QueryInterface $query)
5756
* Get sql.
5857
*
5958
* @param array $sql
59+
*
6060
* @return array
6161
*/
6262
public function getWhereSql(array $sql): array
@@ -70,6 +70,7 @@ public function getWhereSql(array $sql): array
7070
* @param array $sql
7171
* @param array $where
7272
* @param string $conditionType
73+
*
7374
* @return array
7475
*/
7576
public function getConditionSql(array $sql, array $where, string $conditionType): array
@@ -82,7 +83,7 @@ public function getConditionSql(array $sql, array $where, string $conditionType)
8283
$sql[] = $item->getValue();
8384
continue;
8485
}
85-
list($type, $conditions) = $item;
86+
[$type, $conditions] = $item;
8687
if (!$index) {
8788
$whereType = $conditionType;
8889
} else {
@@ -92,9 +93,9 @@ public function getConditionSql(array $sql, array $where, string $conditionType)
9293
$sql[] = $whereType . ' ' . $conditions[0]->getValue();
9394
continue;
9495
}
95-
list($leftField, $operator, $rightField) = $conditions;
96+
[$leftField, $operator, $rightField] = $conditions;
9697
$leftField = $this->quoter->quoteName($leftField);
97-
list($rightField, $operator) = $this->getRightFieldValue($rightField, $operator);
98+
[$rightField, $operator] = $this->getRightFieldValue($rightField, $operator);
9899

99100
$sql[] = sprintf('%s %s %s %s', $whereType, $leftField, $operator, $rightField);
100101
}
@@ -103,12 +104,13 @@ public function getConditionSql(array $sql, array $where, string $conditionType)
103104
}
104105

105106
/**
106-
* Comparison Functions and Operators
107+
* Comparison Functions and Operators.
107108
*
108109
* https://dev.mysql.com/doc/refman/5.7/en/comparison-operators.html
109110
*
110111
* @param mixed $rightField
111112
* @param mixed $comparison
113+
*
112114
* @return array
113115
*/
114116
protected function getRightFieldValue($rightField, $comparison): array
@@ -141,6 +143,7 @@ protected function getRightFieldValue($rightField, $comparison): array
141143
* Get sql.
142144
*
143145
* @param array $sql
146+
*
144147
* @return array
145148
*/
146149
public function getHavingSql(array $sql): array
@@ -154,6 +157,7 @@ public function getHavingSql(array $sql): array
154157
* @param array ...$conditions (field, comparison, value)
155158
* or (field, comparison, new RawExp('table.field'))
156159
* or new RawExp('...')
160+
*
157161
* @return self
158162
*/
159163
public function where($conditions): self
@@ -171,9 +175,10 @@ public function where($conditions): self
171175
/**
172176
* Adds to a clause through a closure, enclosing within parentheses.
173177
*
174-
* @param string $clause The clause to work with, typically 'where' or 'having'.
175-
* @param string $andor Add the condition using this operator, typically 'AND' or 'OR'.
176-
* @param callable $closure The closure that adds to the clause.
178+
* @param string $clause the clause to work with, typically 'where' or 'having'
179+
* @param string $andor add the condition using this operator, typically 'AND' or 'OR'
180+
* @param callable $closure the closure that adds to the clause
181+
*
177182
* @return void
178183
*/
179184
protected function addClauseCondClosure($clause, $andor, $closure)
@@ -196,9 +201,9 @@ protected function addClauseCondClosure($clause, $andor, $closure)
196201
// append an opening parenthesis to the prior set of conditions,
197202
// with AND/OR as needed ...
198203
if ($set) {
199-
$set[] = new RawExp(strtoupper($andor) . " (");
204+
$set[] = new RawExp(strtoupper($andor) . ' (');
200205
} else {
201-
$set[] = new RawExp("(");
206+
$set[] = new RawExp('(');
202207
}
203208

204209
// append the new conditions to the set, with indenting
@@ -207,7 +212,7 @@ protected function addClauseCondClosure($clause, $andor, $closure)
207212
foreach ($sql as $cond) {
208213
$set[] = new RawExp($cond);
209214
}
210-
$set[] = new RawExp(")");
215+
$set[] = new RawExp(')');
211216

212217
// ... then put the full set of conditions back into $this->$clause
213218
$this->$clause = $set;
@@ -221,6 +226,7 @@ protected function addClauseCondClosure($clause, $andor, $closure)
221226
* @param array ...$conditions (field, comparison, value)
222227
* or (field, comparison, new RawExp('table.field'))
223228
* or new RawExp('...')
229+
*
224230
* @return self
225231
*/
226232
public function orWhere($conditions): self
@@ -241,6 +247,7 @@ public function orWhere($conditions): self
241247
* @param array ...$conditions (field, comparison, value)
242248
* or (field, comparison, new RawExp('table.field'))
243249
* or new RawExp('...')
250+
*
244251
* @return self
245252
*/
246253
public function having($conditions): self
@@ -261,6 +268,7 @@ public function having($conditions): self
261268
* @param array ...$conditions (field, comparison, value)
262269
* or (field, comparison, new RawExp('table.field'))
263270
* or new RawExp('...')
271+
*
264272
* @return self
265273
*/
266274
public function orHaving($conditions): self

src/Database/Connection.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@ public function getQuoter()
5858
}
5959

6060
/**
61-
* Retrieving a list of column values
61+
* Retrieving a list of column values.
6262
*
6363
* sample:
6464
* $lists = $db->queryValues('SELECT id FROM table;', 'id');
6565
*
6666
* @param string $sql
6767
* @param string $key
68+
*
6869
* @return array
6970
*/
7071
public function queryValues(string $sql, string $key): array
@@ -79,11 +80,12 @@ public function queryValues(string $sql, string $key): array
7980
}
8081

8182
/**
82-
* Retrieve only the given column of the first result row
83+
* Retrieve only the given column of the first result row.
8384
*
8485
* @param string $sql
8586
* @param string $column
8687
* @param mixed $default
88+
*
8789
* @return mixed|null
8890
*/
8991
public function queryValue(string $sql, string $column, $default = null)
@@ -97,14 +99,15 @@ public function queryValue(string $sql, string $column, $default = null)
9799
}
98100

99101
/**
100-
* Map query result by column as new index
102+
* Map query result by column as new index.
101103
*
102104
* <code>
103105
* $rows = $db->queryMapColumn('SELECT * FROM table;', 'id');
104106
* </code>
105107
*
106108
* @param string $sql
107109
* @param string $key Column name to map as index
110+
*
108111
* @return array
109112
*/
110113
public function queryMapColumn(string $sql, string $key): array

0 commit comments

Comments
 (0)