Skip to content

Commit

Permalink
Merge branch 'refs/heads/development'
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfelles committed Jul 1, 2024
2 parents 1ab65b2 + dd81bd8 commit d3e1893
Show file tree
Hide file tree
Showing 28 changed files with 525 additions and 433 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- 3306:3306
options: --health-cmd="healthcheck.sh --su-mysql --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3

name: PHP 8.1 - MariaDB
name: PHP 8.3 - MariaDB

steps:
- name: Checkout
Expand All @@ -32,7 +32,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.3
ini-values: mysqli.allow_local_infile=On
tools: composer
coverage: xdebug
Expand Down Expand Up @@ -124,7 +124,7 @@ jobs:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

name: PHP 8.1 - MySQL
name: PHP 8.3 - MySQL

steps:
- name: Checkout
Expand All @@ -133,7 +133,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.3
ini-values: mysqli.allow_local_infile=On
tools: composer
coverage: xdebug
Expand Down
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
image: registry.gitlab.com/aplus-framework/images/base:2
image: registry.gitlab.com/aplus-framework/images/base:4

include:
- template: Security/SAST.gitlab-ci.yml
Expand Down
42 changes: 42 additions & 0 deletions .phpstorm.meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,45 @@
1,
argumentsSet('operators')
);
registerArgumentsSet(
'explain_delete',
\Framework\Database\Manipulation\Delete::EXP_EXTENDED,
\Framework\Database\Manipulation\Delete::EXP_FORMAT_JSON,
\Framework\Database\Manipulation\Delete::EXP_PARTITIONS,
'EXTENDED',
'FORMAT=JSON',
'PARTITIONS',
);
expectedArguments(
\Framework\Database\Manipulation\Delete::explain(),
0,
argumentsSet('explain_delete')
);
registerArgumentsSet(
'explain_select',
\Framework\Database\Manipulation\Select::EXP_EXTENDED,
\Framework\Database\Manipulation\Select::EXP_FORMAT_JSON,
\Framework\Database\Manipulation\Select::EXP_PARTITIONS,
'EXTENDED',
'FORMAT=JSON',
'PARTITIONS',
);
expectedArguments(
\Framework\Database\Manipulation\Select::explain(),
0,
argumentsSet('explain_select')
);
registerArgumentsSet(
'explain_update',
\Framework\Database\Manipulation\Update::EXP_EXTENDED,
\Framework\Database\Manipulation\Update::EXP_FORMAT_JSON,
\Framework\Database\Manipulation\Update::EXP_PARTITIONS,
'EXTENDED',
'FORMAT=JSON',
'PARTITIONS',
);
expectedArguments(
\Framework\Database\Manipulation\Update::explain(),
0,
argumentsSet('explain_update')
);
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
}
],
"require": {
"php": ">=8.1",
"php": ">=8.3",
"ext-mysqli": "*",
"aplus/debug": "^3.0",
"aplus/log": "^3.0"
"aplus/debug": "^4.0",
"aplus/log": "^4.0"
},
"require-dev": {
"ext-xdebug": "*",
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"
services:
package:
image: registry.gitlab.com/aplus-framework/images/package:2
image: registry.gitlab.com/aplus-framework/images/package:4
container_name: package-database
working_dir: /package
volumes:
Expand Down
5 changes: 4 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ parameters:
- tests
ignoreErrors:
- '#Access to an undefined property object::\$[a-zA-Z0-9_]+\.#'
- '#Access to an uninitialized readonly property Framework\\Database\\Result\\Field::#'
- '#Call to protected method sql\(\) of class Framework\\Database\\Definition\\Table\\Columns\\Column\.#'
- '#Call to protected method sql\(\) of class Framework\\Database\\Definition\\Table\\Indexes\\IndexDefinition\.#'
- '#Call to protected method sql\(\) of class Framework\\Database\\Definition\\Table\\Indexes\\Index\.#'
- '#Call to protected method sql\(\) of class Framework\\Database\\Definition\\Table\\TableDefinition\.#'
- '#Cannot access offset [0-9]+ on array<int, Framework\\Database\\Result\\Field>\|false\.#'
- '#Class Framework\\Database\\Result\\Field has an uninitialized readonly property#'
- '#Class Framework\\Database\\Result\\Explain has an uninitialized readonly property#'
- '#Readonly property Framework\\Database\\Result\\Field::\$[a-zA-Z0-9_]+ is assigned outside of the constructor.#'
22 changes: 15 additions & 7 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use LogicException;
use mysqli;
use mysqli_sql_exception;
use mysqli_warning;
use RuntimeException;
use SensitiveParameter;

Expand Down Expand Up @@ -198,7 +199,9 @@ protected function connect(
if ($this->failoverIndex === null) {
$this->config = $config;
}
\mysqli_report($config['report']);
if (isset($config['report'])) {
\mysqli_report($config['report']);
}
$this->mysqli = new mysqli();
foreach ($config['options'] as $option => $value) {
$this->mysqli->options($option, $value);
Expand Down Expand Up @@ -345,17 +348,22 @@ public function getConfig() : array
return $this->config;
}

public function warnings() : int
public function getWarningsCount() : int
{
return $this->mysqli->warning_count;
}

public function getWarnings() : false | mysqli_warning
{
return $this->mysqli->get_warnings();
}

/**
* Get a list of the latest errors.
*
* @return array<int,array<string,mixed>>
*/
public function errors() : array
public function getErrors() : array
{
return $this->mysqli->error_list;
}
Expand All @@ -365,7 +373,7 @@ public function errors() : array
*
* @return string|null
*/
public function error() : ?string
public function getError() : ?string
{
return $this->mysqli->error ?: null;
}
Expand Down Expand Up @@ -595,7 +603,7 @@ public function with() : With
return new With($this);
}

public function lastQuery() : string
public function getLastQuery() : string
{
return $this->lastQuery;
}
Expand Down Expand Up @@ -711,7 +719,7 @@ public function transaction(callable $statements) : static
*
* @return int|string
*/
public function insertId() : int | string
public function getInsertId() : int | string
{
return $this->mysqli->insert_id;
}
Expand Down Expand Up @@ -801,7 +809,7 @@ protected function finalizeAddToDebug(
$this->debugCollector->addData([
'start' => $start,
'end' => $end,
'statement' => $this->lastQuery(),
'statement' => $this->getLastQuery(),
'rows' => $rows,
'description' => $description,
]);
Expand Down
22 changes: 22 additions & 0 deletions src/Debug/DatabaseCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types=1);
/*
* This file is part of Aplus Framework Database Library.
*
* (c) Natan Felles <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Framework\Database\Debug;

use Framework\Debug\Collection;

/**
* Class DatabaseCollection.
*
* @package database
*/
class DatabaseCollection extends Collection
{
protected string $iconPath = __DIR__ . '/icons/database.svg';
}
22 changes: 0 additions & 22 deletions src/Debug/DatabaseCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,13 @@
class DatabaseCollector extends Collector
{
protected Database $database;
/**
* @var string
*
* @deprecated Use {@see Database::getConnection()}
*/
protected string $serverInfo;

public function setDatabase(Database $database) : static
{
$this->database = $database;
return $this;
}

/**
* @param string $serverInfo
*
* @deprecated Use {@see Database::getConnection()}
*
* @codeCoverageIgnore
*/
public function setServerInfo(string $serverInfo) : void
{
\trigger_error(
'Method ' . __METHOD__ . ' is deprecated',
\E_USER_DEPRECATED
);
$this->serverInfo = $serverInfo;
}

public function getServerInfo() : string
{
return $this->database->getConnection()->server_info;
Expand Down
1 change: 1 addition & 0 deletions src/Debug/icons/database.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 9 additions & 36 deletions src/Definition/AlterTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,15 @@
*/
class AlterTable extends TableStatement
{
/**
* @var string
*/
public const ALGO_COPY = 'COPY';
/**
* @var string
*/
public const ALGO_DEFAULT = 'DEFAULT';
/**
* @var string
*/
public const ALGO_INPLACE = 'INPLACE';
/**
* @var string
*/
public const ALGO_INSTANT = 'INSTANT';
/**
* @var string
*/
public const ALGO_NOCOPY = 'NOCOPY';
/**
* @var string
*/
public const LOCK_DEFAULT = 'DEFAULT';
/**
* @var string
*/
public const LOCK_EXCLUSIVE = 'EXCLUSIVE';
/**
* @var string
*/
public const LOCK_NONE = 'NONE';
/**
* @var string
*/
public const LOCK_SHARED = 'SHARED';
public const string ALGO_COPY = 'COPY';
public const string ALGO_DEFAULT = 'DEFAULT';
public const string ALGO_INPLACE = 'INPLACE';
public const string ALGO_INSTANT = 'INSTANT';
public const string ALGO_NOCOPY = 'NOCOPY';
public const string LOCK_DEFAULT = 'DEFAULT';
public const string LOCK_EXCLUSIVE = 'EXCLUSIVE';
public const string LOCK_NONE = 'NONE';
public const string LOCK_SHARED = 'SHARED';

/**
* @return static
Expand Down
16 changes: 4 additions & 12 deletions src/Definition/Table/Indexes/Keys/ForeignKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,25 @@ final class ForeignKey extends ConstraintKey
* The change is allowed and propagates on the child table.
* For example, if a parent row is deleted, the child row is also deleted;
* if a parent row's ID changes, the child row's ID will also change.
*
* @var string
*/
public const OPT_CASCADE = 'CASCADE';
public const string OPT_CASCADE = 'CASCADE';
/**
* Synonym for RESTRICT.
*
* @see ForeignKey::OPT_RESTRICT
*
* @var string
*/
public const OPT_NO_ACTION = 'NO ACTION';
public const string OPT_NO_ACTION = 'NO ACTION';
/**
* The change on the parent table is prevented.
* The statement terminates with a 1451 error (SQLSTATE '2300').
* This is the default behavior for both ON DELETE and ON UPDATE.
*
* @var string
*/
public const OPT_RESTRICT = 'RESTRICT';
public const string OPT_RESTRICT = 'RESTRICT';
/**
* The change is allowed, and the child row's foreign key columns are set
* to NULL.
*
* @var string
*/
public const OPT_SET_NULL = 'SET NULL';
public const string OPT_SET_NULL = 'SET NULL';
protected string $type = 'FOREIGN KEY';
protected ?string $referenceTable = null;
/**
Expand Down
Loading

0 comments on commit d3e1893

Please sign in to comment.