From 9eb060aaa223cc948093125e58a95a0de0210c67 Mon Sep 17 00:00:00 2001 From: Karl DeBisschop Date: Wed, 25 Nov 2020 18:06:50 -0500 Subject: [PATCH] Signature of properties must match Step::class --- .gitignore | 4 +++ .php_cs.dist | 40 ++++++++++++++++++++++++ composer.json | 2 +- composer.lock | 2 +- phpcs.xml.dist | 1 + phpstan.neon.dist | 25 +++------------ src/Extractors/GoogleAnalytics.php | 32 ++++++------------- tests/Extractors/GoogleAnalyticsTest.php | 15 ++++----- tests/TestCase.php | 27 +++++++--------- 9 files changed, 80 insertions(+), 68 deletions(-) create mode 100644 .php_cs.dist diff --git a/.gitignore b/.gitignore index 7ddbf75..a9127cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ /vendor/ +/phpdoc/ /.idea/ +/.phpdoc/ +/.phpunit.result.cache +/.php_cs.cache diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..ba2fb31 --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,40 @@ +exclude('vendor') + ->in(__DIR__) +; + +$customRules = [ + '@Symfony' => true, + 'array_syntax' => ['syntax' => 'short'], + 'concat_space' => ['spacing' => 'one'], + 'increment_style' => ['style' => 'post'], + 'declare_strict_types' => true, + 'phpdoc_summary' => false, +]; + +$psr12Rules = [ + '@PSR2' => true, + 'blank_line_after_opening_tag' => true, + 'braces' => ['allow_single_line_closure' => true], + 'compact_nullable_typehint' => true, + 'concat_space' => ['spacing' => 'one'], + 'declare_equal_normalize' => ['space' => 'none'], + 'function_typehint_space' => true, + 'new_with_braces' => true, + 'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'], + 'no_empty_statement' => true, + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_whitespace_in_blank_line' => true, + 'return_type_declaration' => ['space_before' => 'none'], + 'single_trait_insert_per_statement' => true, +]; + +return PhpCsFixer\Config::create() + ->setRules($customRules + $psr12Rules) + ->setFinder($finder) +; diff --git a/composer.json b/composer.json index af45f3e..aecf3a9 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "require": { "php": "~7.4", "google/apiclient": "^2.8", - "wizaplace/php-etl": "^1.2" + "wizaplace/php-etl": "<=1.2.1" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 4964c13..c7709b9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7818bb11934e586dad6507ed2de7c408", + "content-hash": "5c9e6eed8e4da83c4c91a9c8701e1d00", "packages": [ { "name": "firebase/php-jwt", diff --git a/phpcs.xml.dist b/phpcs.xml.dist index d4dcf38..75d6aa2 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -6,4 +6,5 @@ src + tests diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 5fc0feb..48d2fbd 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -3,28 +3,13 @@ parameters: level: 6 paths: - src + - tests checkMissingIterableValueType: false checkGenericClassInNonGenericObjectType: false ignoreErrors: - - message: '~^Variable method call on ~' - path: src/Database/Query.php - + message: '~^Call to an undefined method Prophecy\\Prophecy\\ObjectProphecy::~' + path: tests/Extractors/GoogleAnalyticsTest.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: '~^Access to an undefined property Prophecy\\Prophecy\\ObjectProphecy::~' + path: tests/Extractors/GoogleAnalyticsTest.php diff --git a/src/Extractors/GoogleAnalytics.php b/src/Extractors/GoogleAnalytics.php index 6a72573..2bb862f 100644 --- a/src/Extractors/GoogleAnalytics.php +++ b/src/Extractors/GoogleAnalytics.php @@ -53,7 +53,14 @@ * * ### Input * - * {@see GoogleAnalytics::$input} + * By default, the input is all the web properties the Google client has access to. + * However, an array of property names may be specified to limit the extraction to + * a smaller set of properties. (In the example below, property names correspond to + * the web site name, but that is not necessarily true for all GA users.) + * + * ```php + * $input = ['www.example.com', 'demo.example.com']; + * ``` * * ### Options * - Dimensions (required) {@see GoogleAnalytics::$dimensions} @@ -66,24 +73,8 @@ class GoogleAnalytics extends Extractor { private const REPORT_PAGE_SIZE = 1000; - /** - * The input source. - * - * By default, the input is all the web properties the Google client has access to. - * However, an array of property names may be specified to limit the extraction to - * a smaller set of properties. (In the example below, property names correspond to - * the web site name, but that is not necessarily true for all GA users.) - * - * ```php - * $input = ['www.example.com', 'demo.example.com']; - * ``` - * - * @var string[] - */ - protected array $input = []; - - /** @var string[] */ - protected array $availableOptions = ['startDate', 'endDate', 'views', 'dimensions', 'metrics']; + /** @var array */ + protected $availableOptions = ['startDate', 'endDate', 'views', 'dimensions', 'metrics']; /** * The dimension or dimensions used to group analytics data (frequently "ga:date"). @@ -203,9 +194,6 @@ public function extract(): \Generator $request = $this->reportRequest($profileSummary->getId()); $reports = $this->reportingService->reports->batchGet($request); - if (empty($reports)) { - print_r($request); - } /** @var \Google_Service_AnalyticsReporting_Report $report */ foreach ($reports as $report) { diff --git a/tests/Extractors/GoogleAnalyticsTest.php b/tests/Extractors/GoogleAnalyticsTest.php index 553cb41..4295016 100644 --- a/tests/Extractors/GoogleAnalyticsTest.php +++ b/tests/Extractors/GoogleAnalyticsTest.php @@ -11,32 +11,29 @@ namespace PhpEtl\GoogleAnalytics\Tests\Extractors; -use PhpEtl\GoogleAnalytics\Tests\TestCase; use PhpEtl\GoogleAnalytics\Extractors\GoogleAnalytics; +use PhpEtl\GoogleAnalytics\Tests\TestCase; use Wizaplace\Etl\Row; /** - * Class GoogleAnalyticsTest - * - * @package Tests\Extractors + * Tests GoogleAnalytics. */ class GoogleAnalyticsTest extends TestCase { - protected array $input = []; protected array $options = [ 'startDate' => '2010-11-11', 'dimensions' => ['ga:date'], - 'metrics' => [['name' => 'ga:pageviews', 'type' => 'INTEGER']] + 'metrics' => [['name' => 'ga:pageviews', 'type' => 'INTEGER']], ]; /** @test */ - public function defaultOptions() + public function defaultOptions(): void { $expected = [ - new Row(['id' => 1, 'name' => 'John Doe', 'email' => 'johndoe@email.com']), - new Row(['id' => 2, 'name' => 'Jane Doe', 'email' => 'janedoe@email.com']), + new Row(['id' => '1', 'name' => 'John Doe', 'email' => 'johndoe@email.com']), + new Row(['id' => '2', 'name' => 'Jane Doe', 'email' => 'janedoe@email.com']), ]; $profile = $this->prophesize(\Google_Service_Analytics_ProfileSummary::class); diff --git a/tests/TestCase.php b/tests/TestCase.php index adb974e..ab7cfb9 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -16,31 +16,28 @@ use Wizaplace\Etl\Transformers\Transformer; /** - * Class TestCase - * - * @package Tests + * Base class for PHP-ETL tests. */ abstract class TestCase extends BaseTestCase { - /** - * @param $step - * @param $data + * @param Transformer|Loader $step + * @param array $data */ - protected function execute($step, $data) + protected function execute($step, $data): void { + $step->initialize(); + if ($step instanceof Transformer) { - $method = 'transform'; + foreach ($data as $row) { + $step->transform($row); + } } if ($step instanceof Loader) { - $method = 'load'; - } - - $step->initialize(); - - foreach ($data as $row) { - $step->$method($row); + foreach ($data as $row) { + $step->load($row); + } } $step->finalize();