Skip to content

Commit

Permalink
Merge pull request #18 from Icinga/code-quality-and-conventions
Browse files Browse the repository at this point in the history
Code quality and conventions
  • Loading branch information
lippserd authored Mar 12, 2020
2 parents aaa6382 + 1b5fb97 commit c796206
Show file tree
Hide file tree
Showing 27 changed files with 379 additions and 416 deletions.
11 changes: 4 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# Exclude all hidden files...
# Exclude all hidden files
.*

# Except those related to Git and GitHub
# Except those related to Git (and GitHub)
!.git*
!.github*

# Exclude build and packaging leftovers
/debian
/vendor
build/*
# Exclude files from composer install
vendor/
composer.lock
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2017 Icinga GmbH https://www.icinga.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
17 changes: 3 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,10 @@ for building SQL queries via an OOP API.

For details please see the [features](doc/01-Features.md) description.

## License

This project is licensed under the terms of the GNU General Public License
Version 2 (or later).

This software is Copyright (C) 2018 by the
[Icinga Development Team](https://github.com/Icinga).

## Requirements

* PHP >= v5.6
* PDO extension

## Installation

The recommended way to install this library is via [Composer](https://getcomposer.org):

```
$ composer require ipl/sql
composer require ipl/sql
```
26 changes: 3 additions & 23 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,11 @@
"description": "Icinga PHP Library - SQL abstraction layer",
"keywords": ["sql", "database"],
"homepage": "https://github.com/Icinga/ipl-sql",
"license": "GPL-2.0-or-later",
"authors": [
{
"name": "Alexander A. Klimov",
"email": "[email protected]",
"homepage": "https://github.com/Al2Klimov",
"role": "Developer"
},
{
"name": "Eric Lippmann",
"email": "[email protected]",
"homepage": "https://github.com/lippserd",
"role": "Developer"
},
{
"name": "Thomas Gelf",
"email": "[email protected]",
"homepage": "https://github.com/Thomas-Gelf",
"role": "Developer"
}
],
"license": "MIT",
"require": {
"php": ">=5.4.0",
"php": ">=5.6.0",
"ext-pdo": "*",
"ipl/stdlib": ">=0.1"
"ipl/stdlib": ">=0.5.0"
},
"autoload": {
"psr-4": {
Expand Down
13 changes: 5 additions & 8 deletions src/Adapter/BaseAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use DateTime;
use DateTimeZone;
use PDO;
use ipl\Sql\Connection;
use ipl\Sql\Config;
use ipl\Sql\Connection;
use ipl\Sql\Contract\Adapter;
use PDO;

abstract class BaseAdapter implements AdapterInterface
abstract class BaseAdapter implements Adapter
{
/**
* Quote character to use for quoting identifiers
Expand All @@ -19,11 +20,7 @@ abstract class BaseAdapter implements AdapterInterface
*/
protected $quoteCharacter = ['"', '"'];

/**
* Character to use for escaping quote characters
*
* @var string
*/
/** @var string Character to use for escaping quote characters */
protected $escapeCharacter = '\\"';

/** @var array Default PDO connect options */
Expand Down
4 changes: 2 additions & 2 deletions src/Adapter/Mssql.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace ipl\Sql\Adapter;

use ipl\Sql\Config;
use PDO;
use RuntimeException;
use ipl\Sql\Config;

class Mssql extends BaseAdapter
{
protected $quoteCharacter = ['[', ']'];

protected $escapeCharatcer = '[[]';
protected $escapeCharacter = '[[]';

public function getDsn(Config $config)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Adapter/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace ipl\Sql\Adapter;

use ipl\Sql\Connection;
use ipl\Sql\Config;
use ipl\Sql\Connection;
use PDO;

class Mysql extends BaseAdapter
{
protected $quoteCharacter = ['`', '`'];

protected $escapeCharatcer = '``';
protected $escapeCharacter = '``';

public function setClientTimezone(Connection $db)
{
Expand Down
12 changes: 6 additions & 6 deletions src/CommonTableExpressionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ interface CommonTableExpressionInterface
* ...
* ]
*
* @return array[]
* @return array[]
*/
public function getWith();

/**
* Add a CTE
*
* @param Select $query
* @param string $alias
* @param bool $recursive
* @param Select $query
* @param string $alias
* @param bool $recursive
*
* @return $this
* @return $this
*/
public function with(Select $query, $alias, $recursive = false);

/**
* Reset all CTEs
*
* @return $this
* @return $this
*/
public function resetWith();
}
5 changes: 3 additions & 2 deletions src/Compat/FilterProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Icinga\Data\Filter\FilterExpression;
use Icinga\Data\Filter\FilterNot;
use Icinga\Data\Filter\FilterOr;
use InvalidArgumentException;
use ipl\Sql\Expression;
use ipl\Sql\Sql;

Expand All @@ -26,7 +27,7 @@ public static function assembleFilter(Filter $filter, $level = 0)
}

if (! isset($operator)) {
throw new \InvalidArgumentException(sprintf('Cannot render filter: %s', get_class($filter)));
throw new InvalidArgumentException(sprintf('Cannot render filter: %s', get_class($filter)));
}

if (! $filter->isEmpty()) {
Expand Down Expand Up @@ -70,7 +71,7 @@ public static function assemblePredicate($column, $operator, $expression)
return ["($column NOT IN (?) OR $column IS NULL)" => $expression];
}

throw new \InvalidArgumentException(
throw new InvalidArgumentException(
'Unable to render array expressions with operators other than equal or not equal'
);
} elseif ($operator === '=' && strpos($expression, '*') !== false) {
Expand Down
51 changes: 17 additions & 34 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace ipl\Sql;

use InvalidArgumentException;
use Traversable;

use function ipl\Stdlib\get_php_type;

/**
* SQL connection configuration
Expand All @@ -13,59 +14,41 @@ class Config
/**
* Create a new SQL connection configuration from the given configuration key-value pairs
*
* @param array|Traversable $config Configuration key-value pairs
* @param iterable $config Configuration key-value pairs
*
* @throws InvalidArgumentException If $config is not iterable
*/
public function __construct($config)
{
if (! is_array($config) && ! $config instanceof Traversable) {
throw new InvalidArgumentException('Config expects array or Traversable');
if (! is_iterable($config)) {
throw new InvalidArgumentException(sprintf(
'%s expects parameter one to be iterable, got %s instead',
__METHOD__,
get_php_type($config)
));
}

foreach ($config as $key => $value) {
$this->$key = $value;
}
}

/**
* Type of the DBMS
*
* @var string
*/
/** @var string Type of the DBMS */
public $db;

/**
* Database host
*
* @var string
*/
/** @var string Database host */
public $host;

/**
* Database port
*
* @var int
*/
/** @var int Database port */
public $port;

/**
* Database name
*
* @var string
*/
/** @var string Database name */
public $dbname;

/**
* Username to use for authentication
*
* @var string
*/
/** @var string Username to use for authentication */
public $username;

/**
* Password to use for authentication
*
* @var string
*/
/** @var string Password to use for authentication */
public $password;

/**
Expand Down
Loading

0 comments on commit c796206

Please sign in to comment.