Skip to content

Commit

Permalink
Signature of properties must match Step::class
Browse files Browse the repository at this point in the history
  • Loading branch information
Karl DeBisschop committed Nov 26, 2020
1 parent 17356a3 commit 9eb060a
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 68 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/vendor/
/phpdoc/

/.idea/
/.phpdoc/
/.phpunit.result.cache
/.php_cs.cache
40 changes: 40 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

$finder = PhpCsFixer\Finder::create()
->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)
;
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
<rule ref="PSR12"/>
<rule ref="Generic.PHP.Syntax"/>
<file>src</file>
<file>tests</file>
</ruleset>
25 changes: 5 additions & 20 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 10 additions & 22 deletions src/Extractors/GoogleAnalytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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").
Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 6 additions & 9 deletions tests/Extractors/GoogleAnalyticsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 12 additions & 15 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 9eb060a

Please sign in to comment.