Skip to content

Commit 1880a32

Browse files
committed
Applying PSR-2
1 parent 6bc5e68 commit 1880a32

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+5809
-5314
lines changed

src/Mouf/Database/MagicQuery.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
2+
23
namespace Mouf\Database;
4+
35
use SQLParser\Query\StatementFactory;
46
use SQLParser\SQLParser;
57
use SQLParser\SqlRenderInterface;
@@ -15,7 +17,8 @@ class MagicQuery
1517
/**
1618
* @param Doctrine\DBAL\Connection $connection
1719
*/
18-
public function __construct($connection = null) {
20+
public function __construct($connection = null)
21+
{
1922
$this->connection = $connection;
2023
}
2124

@@ -24,10 +27,12 @@ public function __construct($connection = null) {
2427
* from the SQL.
2528
*
2629
* @param string $sql
27-
* @param array $parameters
30+
* @param array $parameters
31+
*
2832
* @return string
2933
*/
30-
public function build($sql, array $parameters = array()) {
34+
public function build($sql, array $parameters = array())
35+
{
3136
$parser = new SQLParser();
3237
$parsed = $parser->parse($sql);
3338

@@ -38,6 +43,7 @@ public function build($sql, array $parameters = array()) {
3843
$select = StatementFactory::toObject($parsed);
3944

4045
$sql = $select->toSql($parameters, $this->connection, 0, SqlRenderInterface::CONDITION_GUESS);
46+
4147
return $sql;
4248
}
4349
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<?php
2-
namespace Mouf\Database;
32

3+
namespace Mouf\Database;
44

55
class MagicQueryParserException extends \Exception
66
{
7-
8-
}
7+
}
Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
<?php
2+
23
namespace Mouf\Database\QueryWriter\Condition;
34

45
use Mouf\Utils\Common\ConditionInterface\ConditionInterface;
56

67
/**
78
* This condition returns true if the SQL parameter has been passed and is not empty.
8-
*
9+
*
910
* @author David Negrier
1011
*/
11-
class ParamAvailableCondition implements ConditionInterface {
12-
13-
private $parameterName;
14-
15-
/**
16-
* @Important
17-
* @param string $parameterName The name of the parameter to check
18-
*/
19-
public function __construct($parameterName) {
20-
$this->parameterName = $parameterName;
21-
}
22-
23-
/**
24-
* @param string $caller
25-
*/
26-
public function isOk($parameters = null) {
27-
return isset($parameters[$this->parameterName]) && !empty($parameters[$this->parameterName]);
28-
}
29-
}
12+
class ParamAvailableCondition implements ConditionInterface
13+
{
14+
private $parameterName;
15+
16+
/**
17+
* @Important
18+
*
19+
* @param string $parameterName The name of the parameter to check
20+
*/
21+
public function __construct($parameterName)
22+
{
23+
$this->parameterName = $parameterName;
24+
}
25+
26+
/**
27+
* @param string $caller
28+
*/
29+
public function isOk($parameters = null)
30+
{
31+
return isset($parameters[$this->parameterName]) && !empty($parameters[$this->parameterName]);
32+
}
33+
}
Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
11
<?php
2+
23
namespace Mouf\Database\QueryWriter\Condition;
34

45
use Mouf\Utils\Value\ValueUtils;
5-
66
use Mouf\Utils\Value\ValueInterface;
7-
87
use Mouf\Utils\Common\ConditionInterface\ConditionInterface;
98

109
/**
1110
* This condition returns true if the SQL parameter is equal to the passed value.
12-
*
11+
*
1312
* @author David Negrier
1413
*/
15-
class ParamEqualsCondition implements ConditionInterface {
16-
17-
private $parameterName;
18-
private $value;
19-
20-
/**
21-
* @Important
22-
* @param string $parameterName The name of the parameter to check
23-
* @param string|ValueInterface $value
24-
*/
25-
public function __construct($parameterName, $value) {
26-
$this->parameterName = $parameterName;
27-
$this->value = $value;
28-
}
29-
30-
/**
31-
* @param string $caller
32-
*/
33-
public function isOk($parameters = null) {
34-
return isset($parameters[$this->parameterName]) && $parameters[$this->parameterName] == ValueUtils::val($this->value);
35-
}
36-
}
14+
class ParamEqualsCondition implements ConditionInterface
15+
{
16+
private $parameterName;
17+
private $value;
18+
19+
/**
20+
* @Important
21+
*
22+
* @param string $parameterName The name of the parameter to check
23+
* @param string|ValueInterface $value
24+
*/
25+
public function __construct($parameterName, $value)
26+
{
27+
$this->parameterName = $parameterName;
28+
$this->value = $value;
29+
}
30+
31+
/**
32+
* @param string $caller
33+
*/
34+
public function isOk($parameters = null)
35+
{
36+
return isset($parameters[$this->parameterName]) && $parameters[$this->parameterName] == ValueUtils::val($this->value);
37+
}
38+
}
Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
<?php
2+
23
namespace Mouf\Database\QueryWriter\Condition;
34

45
use Mouf\Utils\Common\ConditionInterface\ConditionInterface;
56

67
/**
78
* This condition returns true if the SQL parameter has not been passed or if it is empty.
8-
*
9+
*
910
* @author David Negrier
1011
*/
11-
class ParamNotAvailableCondition implements ConditionInterface {
12-
13-
private $parameterName;
14-
15-
/**
16-
* @Important
17-
* @param string $parameterName The name of the parameter to check
18-
*/
19-
public function __construct($parameterName) {
20-
$this->parameterName = $parameterName;
21-
}
22-
23-
/**
24-
* @param string $caller
25-
*/
26-
public function isOk($parameters = null) {
27-
return !isset($parameters[$this->parameterName]) || empty($parameters[$this->parameterName]);
28-
}
29-
}
12+
class ParamNotAvailableCondition implements ConditionInterface
13+
{
14+
private $parameterName;
15+
16+
/**
17+
* @Important
18+
*
19+
* @param string $parameterName The name of the parameter to check
20+
*/
21+
public function __construct($parameterName)
22+
{
23+
$this->parameterName = $parameterName;
24+
}
25+
26+
/**
27+
* @param string $caller
28+
*/
29+
public function isOk($parameters = null)
30+
{
31+
return !isset($parameters[$this->parameterName]) || empty($parameters[$this->parameterName]);
32+
}
33+
}
Lines changed: 55 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,55 @@
1-
<?php
2-
namespace Mouf\Database\QueryWriter;
3-
4-
use Doctrine\DBAL\Connection;
5-
use Mouf\Utils\Value\IntValueInterface;
6-
7-
/**
8-
* A utility class that can compute the number of results returned by a query.
9-
* It does so by embedding the query into a SELECT count(*) query and computing the results.
10-
*
11-
* @Renderer { "smallLogo":"vendor/mouf/database.querywriter/icons/database_query.png" }
12-
* @author David Negrier
13-
*/
14-
class CountNbResult implements IntValueInterface {
15-
16-
/**
17-
* The Select statement.
18-
*
19-
* @var QueryResult
20-
*/
21-
private $queryResult;
22-
23-
/**
24-
* The connection to the database.
25-
*
26-
* @var Connection
27-
*/
28-
private $connection;
29-
30-
/**
31-
* @Important $select
32-
* @param QueryResult $queryResult The query we will perform "count" upon.
33-
* @param Connection $connection
34-
*/
35-
public function __construct(QueryResult $queryResult, Connection $connection) {
36-
$this->queryResult = $queryResult;
37-
$this->connection = $connection;
38-
}
39-
40-
/**
41-
* (non-PHPdoc)
42-
* @see \Mouf\Utils\Value\ArrayValueInterface::val()
43-
*/
44-
public function val() {
45-
$sql = "SELECT count(*) as cnt FROM (".$this->queryResult->toSql().") tmp";
46-
return $this->connection->fetchColumn($sql);
47-
}
48-
49-
}
1+
<?php
2+
3+
namespace Mouf\Database\QueryWriter;
4+
5+
use Doctrine\DBAL\Connection;
6+
use Mouf\Utils\Value\IntValueInterface;
7+
8+
/**
9+
* A utility class that can compute the number of results returned by a query.
10+
* It does so by embedding the query into a SELECT count(*) query and computing the results.
11+
*
12+
* @Renderer { "smallLogo":"vendor/mouf/database.querywriter/icons/database_query.png" }
13+
*
14+
* @author David Negrier
15+
*/
16+
class CountNbResult implements IntValueInterface
17+
{
18+
/**
19+
* The Select statement.
20+
*
21+
* @var QueryResult
22+
*/
23+
private $queryResult;
24+
25+
/**
26+
* The connection to the database.
27+
*
28+
* @var Connection
29+
*/
30+
private $connection;
31+
32+
/**
33+
* @Important $select
34+
*
35+
* @param QueryResult $queryResult The query we will perform "count" upon.
36+
* @param Connection $connection
37+
*/
38+
public function __construct(QueryResult $queryResult, Connection $connection)
39+
{
40+
$this->queryResult = $queryResult;
41+
$this->connection = $connection;
42+
}
43+
44+
/**
45+
* (non-PHPdoc).
46+
*
47+
* @see \Mouf\Utils\Value\ArrayValueInterface::val()
48+
*/
49+
public function val()
50+
{
51+
$sql = 'SELECT count(*) as cnt FROM ('.$this->queryResult->toSql().') tmp';
52+
53+
return $this->connection->fetchColumn($sql);
54+
}
55+
}

0 commit comments

Comments
 (0)