Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refacto Query / Statement #118

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
if [[ ! -f vendor/autoload.php ]]; then
curl https://getcomposer.org/composer-stable.phar --location --silent --output /usr/bin/composer; \
chmod +x /usr/bin/composer; \
composer install --no-progress --no-interaction; \
composer install --no-progress --no-interaction --ignore-platform-req=ext-xdebug; \
fi
- save_cache:
key: composer-{{ checksum "composer.json" }}-{{ checksum "composer.lock" }}
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
if [[ ! -f vendor/autoload.php ]]; then
curl https://getcomposer.org/composer-stable.phar --location --silent --output /usr/bin/composer; \
chmod +x /usr/bin/composer; \
composer install --no-progress --no-interaction; \
composer install --no-progress --no-interaction --ignore-platform-req=ext-xdebug; \
fi
- save_cache:
key: composer-{{ checksum "composer.json" }}-{{ checksum "composer.lock" }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ composer.lock
.phpunit.cache
.idea
var/
cov.xml

# For these quality tools, the *.dist form should be in VCS and the forms
# below should be reserved for local customizations.
Expand Down
17 changes: 14 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
dev:
nix shell github:loophp/nix-shell --impure

phpcs:
vendor/bin/phpcs -n
vendor/bin/phpcs -n --parallel=8

phpcbf:
vendor/bin/phpcbf

phpstan:
vendor/bin/phpstan clear-result-cache
vendor/bin/phpstan analyse
php -d memory_limit=2G vendor/bin/phpstan analyse

phpcsfixer:
vendor/bin/php-cs-fixer fix --dry-run --allow-risky=yes --diff
Expand All @@ -15,4 +18,12 @@ test:
vendor/bin/phpunit --testdox

infection:
vendor/bin/infection
XDEBUG_MODE=coverage vendor/bin/infection -j8

PHPUNIT_REPORT_PATH = /tmp/phpunit_coverage_report
coverage:
XDEBUG_MODE=coverage vendor/bin/phpunit \
--coverage-clover cov.xml \
--coverage-filter src \
--coverage-html $(PHPUNIT_REPORT_PATH)
xdg-open $(PHPUNIT_REPORT_PATH)/index.html
9 changes: 9 additions & 0 deletions changelog.MD
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## Next version

**Bugfixes**
* Use backticks `` ` `` for table and column names in `Wizaplace\Etl\Database\*` classes (see https://github.com/wizacode/php-etl/issues/117)

**Miscellaneous**
* Nix shell dev environment `Makefile` command
* Code coverage `Makefile` command

## 2.3
* Add the PHPDoc _@mixin Pipeline_ to the Etl class.
* Add _mixed_ return type to _Wizaplace\Etl\Row\offsetGet_.
Expand Down
25 changes: 19 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
{
"name": "wizaplace/php-etl",
"description": "Extract, Transform and Load data using this PHP written migration library.",
"keywords": ["etl", "extract", "transform", "load", "extraction", "transformation", "data", "symfony"],
"keywords": [
"etl",
"extract",
"transform",
"load",
"extraction",
"transformation",
"data",
"symfony"
],
"license": "MIT",
"authors": [
{
Expand All @@ -22,7 +31,7 @@
},
"require": {
"php": "~8.1",
"softcreatr/jsonpath": "^0.7.2"
"softcreatr/jsonpath": "^0.8.3"
},
"autoload": {
"psr-4": {
Expand All @@ -34,12 +43,13 @@
"ext-json": "*",
"ext-pdo_sqlite": "*",
"ext-xmlreader": "*",
"ext-xdebug": "*",
"friendsofphp/php-cs-fixer": "^3.4",
"infection/infection": ">=0.15",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.100",
"phpstan/phpstan-deprecation-rules": "^0.12.6",
"phpstan/phpstan-strict-rules": "^0.12.11",
"phpstan/phpstan": "^1.11",
"phpstan/phpstan-deprecation-rules": "^1.1.4",
"phpstan/phpstan-strict-rules": "^1.5.1",
"phpunit/phpunit": ">=8",
"squizlabs/php_codesniffer": "^3.5"
},
Expand All @@ -64,7 +74,10 @@
"phpstan --memory-limit=256M analyze"
],
"test": "phpunit",
"check": ["@scan", "@test"]
"check": [
"@scan",
"@test"
]
},
"minimum-stability": "dev",
"prefer-stable": true
Expand Down
2 changes: 1 addition & 1 deletion docs/Extractors/Table.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ $options = [Table::CONNECTION => 'app'];
Array of conditions, each condition is either:

- `key` equals `value` , or
- `key` _comparesTo_ `value` (comparesTo can be: =, <, <=, =>, >, or <>).
- `key` _comparesTo_ `value` (comparesTo can be: =, <, <=, >=, >, or <>).

If you need more flexibility in the query creation, you may use the [Query extractor](Query.md).

Expand Down
66 changes: 33 additions & 33 deletions docs/img/etl.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion infection.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
}
},
"testFramework":"phpunit",
"testFrameworkOptions": "-vvv"

}
19 changes: 0 additions & 19 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,16 @@ parameters:
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
ignoreErrors:
-
message: '~^Variable method call on ~'
path: src/Database/Query.php

-
message: '~^Variable method call on ~'
path: src/Database/Statement.php

-
message: '~^Variable method call on ~'
path: src/Etl.php

-
message: '~^Variable property access on ~'
path: src/Row.php

-
message: '~^Variable property access on ~'
path: src/Step.php
-
message: '~^Dynamic call to static method XMLReader::open\(\)\.~'
path: src/Extractors\Xml.php
-
message: '~Variable method call on Wizaplace\\Etl\\Step\.~'
path: tests/Tools/AbstractTestCase.php
-
message: '~Access to an undefined property Wizaplace\\Etl\\Row::\$name\.~'
path: tests/Unit/RowTest.php
-
message: '~Method Wizaplace\\Etl\\Row::offsetGet\(\) has no return typehint specified.~'
path: src/Row.php

39 changes: 20 additions & 19 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
bootstrap="vendor/autoload.php"
colors="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
displayDetailsOnTestsThatTriggerWarnings="true"
failOnEmptyTestSuite="true"
failOnIncomplete="true"
failOnRisky="true"
failOnSkipped="true"
failOnWarning="true"
backupGlobals="false"
bootstrap="vendor/autoload.php"
colors="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
displayDetailsOnTestsThatTriggerWarnings="true"
failOnEmptyTestSuite="true"
failOnIncomplete="true"
failOnRisky="true"
failOnSkipped="true"
failOnWarning="true"
>
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<coverage/>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/Unit</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
38 changes: 38 additions & 0 deletions src/Database/Helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* @author Wizacha DevTeam <[email protected]>
* @copyright Copyright (c) Wizacha
* @copyright Copyright (c) Leonardo Marquine
* @license MIT
*/

declare(strict_types=1);

namespace Wizaplace\Etl\Database;

class Helpers
{
public const DEFAULT_MASK = '{column}';
public const BACKTICKED_MASK = '`{column}`';

/**
* Join array elements using a string mask.
*/
public static function implode(
array $columns,
string $mask = self::DEFAULT_MASK,
array $ignoreMask = ['*'] // No backticks for *
): string {
$columns = array_map(
function ($column) use ($mask, $ignoreMask): string {
return \in_array($column, $ignoreMask, true)
? $column
: str_replace(self::DEFAULT_MASK, $column, $mask);
},
$columns
);

return implode(', ', $columns);
}
}
Loading