From bbb22ab5028e50cd93150ac4c3cd9f7d39d3ff80 Mon Sep 17 00:00:00 2001 From: Lio Novelli Date: Mon, 2 Jan 2023 22:03:59 +0100 Subject: [PATCH] Work on code style. --- app/composer.json | 8 +- app/composer.lock | 166 +++++++++++------- app/phpcs.xml | 10 +- app/src/Commands/InvoiceCommand.php | 19 +- app/src/Commands/ReportCommand.php | 6 +- app/src/Commands/SelectReportTrait.php | 2 +- app/src/Commands/TrackCommand.php | 2 +- .../Configuration/ConfigurationInterface.php | 4 +- .../Configuration/ConfigurationService.php | 4 +- app/src/Utils/CsvReport/CsvReport.php | 12 +- .../Utils/CsvReport/CsvReportInterface.php | 4 +- app/src/Utils/CsvReport/ReportCsv.php | 23 ++- .../Utils/CsvReport/ReportCsvInterface.php | 8 +- app/src/Utils/Mailer/MailerInterface.php | 8 +- app/src/Utils/Mailer/MailerService.php | 16 +- .../Utils/PdfExport/PdfExportInterface.php | 16 +- app/src/Utils/PdfExport/PdfExportService.php | 22 +-- .../YoutrackInterface.php | 16 +- .../TimeTrackingServices/YoutrackService.php | 24 +-- app/tests/Kernel/ReportCommandTest.php | 26 +-- app/tests/test-dependencies.php | 4 +- todo.txt | 4 +- 22 files changed, 225 insertions(+), 179 deletions(-) diff --git a/app/composer.json b/app/composer.json index 0a7a2ef..0e679bf 100644 --- a/app/composer.json +++ b/app/composer.json @@ -30,14 +30,14 @@ "require-dev": { "squizlabs/php_codesniffer": "^3.7", "phpunit/phpunit": "^9.5", - "opsway/psr12-strict-coding-standard": "^0.5.0", + "opsway/psr12-strict-coding-standard": "^1.0", "phpcompatibility/php-compatibility": "^9.3", "phpstan/phpstan": "^1.9" }, "scripts": { - "cs": "phpcs --colors --standard=PSR12", - "cbf": "phpcbf", - "phpstan": "phpstan analyze -l 5 src" + "cs": "vendor/bin/phpcs --colors", + "cbf": "vendor/bin/phpcbf", + "phpstan": "vendor/bin/phpstan analyze -l 5 src" }, "config": { "allow-plugins": { diff --git a/app/composer.lock b/app/composer.lock index eb35a5a..c8af7f2 100644 --- a/app/composer.lock +++ b/app/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": "eb0c874610e45fa74d8ccc691f5bd9f8", + "content-hash": "dcf2d10608163dc9004a26e38e06a533", "packages": [ { "name": "doctrine/lexer", @@ -2603,27 +2603,27 @@ "packages-dev": [ { "name": "dealerdirect/phpcodesniffer-composer-installer", - "version": "v0.7.1", + "version": "v0.7.2", "source": { "type": "git", "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", - "reference": "fe390591e0241955f22eb9ba327d137e501c771c" + "reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/fe390591e0241955f22eb9ba327d137e501c771c", - "reference": "fe390591e0241955f22eb9ba327d137e501c771c", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db", + "reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db", "shasum": "" }, "require": { "composer-plugin-api": "^1.0 || ^2.0", "php": ">=5.3", - "squizlabs/php_codesniffer": "^2.0 || ^3.0 || ^4.0" + "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" }, "require-dev": { "composer/composer": "*", - "phpcompatibility/php-compatibility": "^9.0", - "sensiolabs/security-checker": "^4.1.0" + "php-parallel-lint/php-parallel-lint": "^1.3.1", + "phpcompatibility/php-compatibility": "^9.0" }, "type": "composer-plugin", "extra": { @@ -2644,6 +2644,10 @@ "email": "franck.nijhof@dealerdirect.com", "homepage": "http://www.frenck.nl", "role": "Developer / IT Manager" + }, + { + "name": "Contributors", + "homepage": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer/graphs/contributors" } ], "description": "PHP_CodeSniffer Standards Composer Installer Plugin", @@ -2655,6 +2659,7 @@ "codesniffer", "composer", "installer", + "phpcbf", "phpcs", "plugin", "qa", @@ -2665,7 +2670,11 @@ "stylecheck", "tests" ], - "time": "2020-12-07T18:04:37+00:00" + "support": { + "issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues", + "source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer" + }, + "time": "2022-02-04T12:51:07+00:00" }, { "name": "doctrine/instantiator", @@ -2795,30 +2804,29 @@ }, { "name": "opsway/psr12-strict-coding-standard", - "version": "0.5.0", + "version": "1.0.0", "source": { "type": "git", "url": "https://github.com/opsway/psr12-strict-modern-standart.git", - "reference": "495d5109079f544ec46ec2f0e2161d48f62a6335" + "reference": "2ce8d92f35ed3c229b1da2668c7c02c490af95f4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/opsway/psr12-strict-modern-standart/zipball/495d5109079f544ec46ec2f0e2161d48f62a6335", - "reference": "495d5109079f544ec46ec2f0e2161d48f62a6335", + "url": "https://api.github.com/repos/opsway/psr12-strict-modern-standart/zipball/2ce8d92f35ed3c229b1da2668c7c02c490af95f4", + "reference": "2ce8d92f35ed3c229b1da2668c7c02c490af95f4", "shasum": "" }, "require": { - "dealerdirect/phpcodesniffer-composer-installer": "~0.6", - "php": "^7.3 || ^8.0", - "slevomat/coding-standard": "^6.1", - "squizlabs/php_codesniffer": "^3.5", - "webimpress/coding-standard": "^1.1" + "dealerdirect/phpcodesniffer-composer-installer": "~0.7", + "php": "^8.0", + "slevomat/coding-standard": "^7.0 || ^8.0", + "squizlabs/php_codesniffer": "^3.6 || ^4.0", + "webimpress/coding-standard": "^1.2" }, "type": "phpcodesniffer-standard", "extra": { "branch-alias": { - "dev-master": "0.0.x-dev", - "dev-develop": "1.0.x-dev" + "dev-develop": "2.0.x-dev" } }, "autoload": { @@ -2836,7 +2844,13 @@ "opsway", "psr12-strict" ], - "time": "2021-01-01T11:19:18+00:00" + "support": { + "docs": "https://github.com/opsway/psr12-strict-modern-standart/tree/master/docs", + "issues": "https://github.com/opsway/psr12-strict-modern-standart/issues", + "rss": "https://github.com/opsway/psr12-strict-modern-standart/releases.atom", + "source": "https://github.com/opsway/psr12-strict-modern-standart" + }, + "time": "2022-10-22T12:21:38+00:00" }, { "name": "phar-io/manifest", @@ -3240,39 +3254,31 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "0.4.9", + "version": "1.15.3", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "98a088b17966bdf6ee25c8a4b634df313d8aa531" + "reference": "61800f71a5526081d1b5633766aa88341f1ade76" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/98a088b17966bdf6ee25c8a4b634df313d8aa531", - "reference": "98a088b17966bdf6ee25c8a4b634df313d8aa531", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/61800f71a5526081d1b5633766aa88341f1ade76", + "reference": "61800f71a5526081d1b5633766aa88341f1ade76", "shasum": "" }, "require": { - "php": "^7.1 || ^8.0" + "php": "^7.2 || ^8.0" }, "require-dev": { - "consistence/coding-standard": "^3.5", - "ergebnis/composer-normalize": "^2.0.2", - "jakub-onderka/php-parallel-lint": "^0.9.2", - "phing/phing": "^2.16.0", + "php-parallel-lint/php-parallel-lint": "^1.2", "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^0.12.26", - "phpstan/phpstan-strict-rules": "^0.12", - "phpunit/phpunit": "^6.3", - "slevomat/coding-standard": "^4.7.2", - "symfony/process": "^4.0" + "phpstan/phpstan": "^1.5", + "phpstan/phpstan-phpunit": "^1.1", + "phpstan/phpstan-strict-rules": "^1.0", + "phpunit/phpunit": "^9.5", + "symfony/process": "^5.2" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.4-dev" - } - }, "autoload": { "psr-4": { "PHPStan\\PhpDocParser\\": [ @@ -3285,7 +3291,11 @@ "MIT" ], "description": "PHPDoc parser with support for nullable, intersection and generic types", - "time": "2020-08-03T20:32:43+00:00" + "support": { + "issues": "https://github.com/phpstan/phpdoc-parser/issues", + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.15.3" + }, + "time": "2022-12-20T20:56:55+00:00" }, { "name": "phpstan/phpstan", @@ -4733,37 +4743,37 @@ }, { "name": "slevomat/coding-standard", - "version": "6.4.1", + "version": "8.7.1", "source": { "type": "git", "url": "https://github.com/slevomat/coding-standard.git", - "reference": "696dcca217d0c9da2c40d02731526c1e25b65346" + "reference": "c51edb898bebd36aac70a190c6a41a7c056bb5b9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/696dcca217d0c9da2c40d02731526c1e25b65346", - "reference": "696dcca217d0c9da2c40d02731526c1e25b65346", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/c51edb898bebd36aac70a190c6a41a7c056bb5b9", + "reference": "c51edb898bebd36aac70a190c6a41a7c056bb5b9", "shasum": "" }, "require": { "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7", - "php": "^7.1 || ^8.0", - "phpstan/phpdoc-parser": "0.4.5 - 0.4.9", - "squizlabs/php_codesniffer": "^3.5.6" + "php": "^7.2 || ^8.0", + "phpstan/phpdoc-parser": ">=1.15.0 <1.16.0", + "squizlabs/php_codesniffer": "^3.7.1" }, "require-dev": { - "phing/phing": "2.16.3", - "php-parallel-lint/php-parallel-lint": "1.2.0", - "phpstan/phpstan": "0.12.48", - "phpstan/phpstan-deprecation-rules": "0.12.5", - "phpstan/phpstan-phpunit": "0.12.16", - "phpstan/phpstan-strict-rules": "0.12.5", - "phpunit/phpunit": "7.5.20|8.5.5|9.4.0" + "phing/phing": "2.17.4", + "php-parallel-lint/php-parallel-lint": "1.3.2", + "phpstan/phpstan": "1.4.10|1.9.3", + "phpstan/phpstan-deprecation-rules": "1.1.0", + "phpstan/phpstan-phpunit": "1.0.0|1.3.1", + "phpstan/phpstan-strict-rules": "1.4.4", + "phpunit/phpunit": "7.5.20|8.5.21|9.5.27" }, "type": "phpcodesniffer-standard", "extra": { "branch-alias": { - "dev-master": "6.x-dev" + "dev-master": "8.x-dev" } }, "autoload": { @@ -4776,7 +4786,25 @@ "MIT" ], "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", - "time": "2020-10-05T12:39:37+00:00" + "keywords": [ + "dev", + "phpcs" + ], + "support": { + "issues": "https://github.com/slevomat/coding-standard/issues", + "source": "https://github.com/slevomat/coding-standard/tree/8.7.1" + }, + "funding": [ + { + "url": "https://github.com/kukulich", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/slevomat/coding-standard", + "type": "tidelift" + } + ], + "time": "2022-12-14T08:49:18+00:00" }, { "name": "squizlabs/php_codesniffer", @@ -4886,24 +4914,24 @@ }, { "name": "webimpress/coding-standard", - "version": "1.2.1", + "version": "1.2.4", "source": { "type": "git", "url": "https://github.com/webimpress/coding-standard.git", - "reference": "fbeb31ee876b3c493779d3aa717ebb57ef258e6a" + "reference": "cd0c4b0b97440c337c1f7da17b524674ca2f9ca9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webimpress/coding-standard/zipball/fbeb31ee876b3c493779d3aa717ebb57ef258e6a", - "reference": "fbeb31ee876b3c493779d3aa717ebb57ef258e6a", + "url": "https://api.github.com/repos/webimpress/coding-standard/zipball/cd0c4b0b97440c337c1f7da17b524674ca2f9ca9", + "reference": "cd0c4b0b97440c337c1f7da17b524674ca2f9ca9", "shasum": "" }, "require": { "php": "^7.3 || ^8.0", - "squizlabs/php_codesniffer": "^3.5.8" + "squizlabs/php_codesniffer": "^3.6.2" }, "require-dev": { - "phpunit/phpunit": "^9.4.3" + "phpunit/phpunit": "^9.5.13" }, "type": "phpcodesniffer-standard", "extra": { @@ -4927,7 +4955,17 @@ "psr-12", "webimpress" ], - "time": "2021-01-11T18:13:55+00:00" + "support": { + "issues": "https://github.com/webimpress/coding-standard/issues", + "source": "https://github.com/webimpress/coding-standard/tree/1.2.4" + }, + "funding": [ + { + "url": "https://github.com/michalbundyra", + "type": "github" + } + ], + "time": "2022-02-15T19:52:12+00:00" }, { "name": "webmozart/assert", diff --git a/app/phpcs.xml b/app/phpcs.xml index 7264bbf..50e669d 100644 --- a/app/phpcs.xml +++ b/app/phpcs.xml @@ -7,14 +7,18 @@ - + + tests src - test - + + + + + diff --git a/app/src/Commands/InvoiceCommand.php b/app/src/Commands/InvoiceCommand.php index 1490915..71a3d90 100644 --- a/app/src/Commands/InvoiceCommand.php +++ b/app/src/Commands/InvoiceCommand.php @@ -27,10 +27,10 @@ use function explode; use function is_array; use function is_null; use function is_string; -use function PHPUnit\Framework\throwException; use function readline; use function strpos; use function strtolower; +use function sys_get_temp_dir; use function var_dump; use function var_export; @@ -75,7 +75,7 @@ class InvoiceCommand extends Command /** * Get configuration. */ - protected function configure(): void + protected function configure() : void { $this->setName('invoice'); $this->setDescription('Generate an invoice from (monthly) report'); @@ -154,7 +154,7 @@ class InvoiceCommand extends Command ); } - protected function execute(InputInterface $input, OutputInterface $output): int + protected function execute(InputInterface $input, OutputInterface $output) : int { if ($input->getOption('test')) { $test = $this->trackingService->testYoutrackapi(); @@ -205,7 +205,7 @@ class InvoiceCommand extends Command return Command::SUCCESS; } - protected function getTable(OutputInterface $output, array $data): Table + protected function getTable(OutputInterface $output, array $data) : Table { $rows = $this->csv->generateTable($data); $table = new Table($output); @@ -233,7 +233,7 @@ class InvoiceCommand extends Command * @deprecated * This method was almost exact copy of CsvReport::arangeDataForDefaultPdfExport */ - protected function generateTable(OutputInterface $output, array $data): Table + protected function generateTable(OutputInterface $output, array $data) : Table { $table = new Table($output); $table->setHeaders([ @@ -276,7 +276,7 @@ class InvoiceCommand extends Command $rows[] = new TableSeparator(); // @TODO Check rate in final result. // $rows[] = [$this->translator->trans('Sum'), $totalHours, $config['price'], $totalPrice]; - $rows[] = ['Sum', $totalHours, NULL, $totalPrice]; + $rows[] = ['Sum', $totalHours, null, $totalPrice]; $table->setRows($rows); return $table; @@ -285,7 +285,7 @@ class InvoiceCommand extends Command /** * Dummy output for testing. */ - protected function dummyOutput(InputInterface $input, OutputInterface $output): void + protected function dummyOutput(InputInterface $input, OutputInterface $output) : void { // $txt = $this->translator->trans('From [start-date] to [end-date].', [], 'rprt', 'sl_SI'); // $output->writeln($txt); @@ -345,9 +345,8 @@ class InvoiceCommand extends Command } elseif ($type === self::TYPE_EXPENSE) { $message_name = 'Enter expenses name or leave empty to stop: '; $message_value = 'Enter expenses value: '; - } - else { - throw new \Exception('Unknown type of custom data.'); + } else { + throw new Exception('Unknown type of custom data.'); } while ($continue) { $name = readline($message_name); diff --git a/app/src/Commands/ReportCommand.php b/app/src/Commands/ReportCommand.php index e2950ae..a498658 100644 --- a/app/src/Commands/ReportCommand.php +++ b/app/src/Commands/ReportCommand.php @@ -38,7 +38,7 @@ class ReportCommand extends Command parent::__construct($name); } - protected function configure(): void + protected function configure() : void { $this->setName('report'); $this->setDescription('Get a time-tracking report into command line.'); @@ -65,7 +65,7 @@ class ReportCommand extends Command ); } - protected function execute(InputInterface $input, OutputInterface $output): int + protected function execute(InputInterface $input, OutputInterface $output) : int { if ($timeRange = $input->getOption('time-range')) { // @TODO: Implement time range option: @@ -95,7 +95,7 @@ class ReportCommand extends Command * * @TODO: Code duplication with InvoiceCommand::getTable. */ - protected function buildTable(OutputInterface $output, array $rows): Table + protected function buildTable(OutputInterface $output, array $rows) : Table { $table = new Table($output); $table->setHeaders([ diff --git a/app/src/Commands/SelectReportTrait.php b/app/src/Commands/SelectReportTrait.php index 28414c5..7a83ad9 100644 --- a/app/src/Commands/SelectReportTrait.php +++ b/app/src/Commands/SelectReportTrait.php @@ -71,7 +71,7 @@ trait SelectReportTrait InputInterface $input, OutputInterface $output, ?string $default = 'tracking_service.youtrack.report.report' - ): ?string { + ) : ?string { if (! $file = $input->getOption('file')) { $this->getReportParameter($input, $output, $default); $report_id = $this->trackingService->getReportId(); diff --git a/app/src/Commands/TrackCommand.php b/app/src/Commands/TrackCommand.php index 538030e..0eac105 100644 --- a/app/src/Commands/TrackCommand.php +++ b/app/src/Commands/TrackCommand.php @@ -30,7 +30,7 @@ class TrackCommand extends Command parent::__construct($name); } - protected function configure(): void + protected function configure() : void { $this->setName('youtrack'); $this->setDescription('Track time into your youtrack service'); diff --git a/app/src/Utils/Configuration/ConfigurationInterface.php b/app/src/Utils/Configuration/ConfigurationInterface.php index 75e6793..b8ee77b 100644 --- a/app/src/Utils/Configuration/ConfigurationInterface.php +++ b/app/src/Utils/Configuration/ConfigurationInterface.php @@ -11,7 +11,7 @@ interface ConfigurationInterface /** * Get and read the configuration from file. */ - public function getConfig(): bool; + public function getConfig() : bool; /** * Get a specific configuration for key. @@ -31,5 +31,5 @@ interface ConfigurationInterface * @param string $key * Key to check for. */ - public function exists($key): bool; + public function exists($key) : bool; } diff --git a/app/src/Utils/Configuration/ConfigurationService.php b/app/src/Utils/Configuration/ConfigurationService.php index 064ae23..5598f07 100644 --- a/app/src/Utils/Configuration/ConfigurationService.php +++ b/app/src/Utils/Configuration/ConfigurationService.php @@ -77,7 +77,7 @@ class ConfigurationService implements ConfigurationInterface /** * Get and read the configuration from file. */ - public function getConfig(): bool + public function getConfig() : bool { if ($this->configFilePath) { $config = Yaml::parseFile($this->configFilePath); @@ -125,7 +125,7 @@ class ConfigurationService implements ConfigurationInterface * * Value of configuration key is not equal to default. */ - public function exists($key): bool + public function exists($key) : bool { return $this->get($key) !== $this->default; } diff --git a/app/src/Utils/CsvReport/CsvReport.php b/app/src/Utils/CsvReport/CsvReport.php index 06547c8..a30c1be 100644 --- a/app/src/Utils/CsvReport/CsvReport.php +++ b/app/src/Utils/CsvReport/CsvReport.php @@ -39,7 +39,7 @@ class CsvReport implements CsvReportInterface /** * {@inheritdoc} */ - public function getInvoiceData(string $filePath): array + public function getInvoiceData(string $filePath) : array { $output = []; // @TODO replace with config service. @@ -69,7 +69,7 @@ class CsvReport implements CsvReportInterface * * Project key and unit of time spent. */ - protected function parseCsvFile(array $rawData): array + protected function parseCsvFile(array $rawData) : array { $config = $this->configurationService->get('projects'); foreach ($config as $key => $project) { @@ -80,7 +80,7 @@ class CsvReport implements CsvReportInterface return []; } - public function arangeDataForDefaultPdfExport(array $data): array + public function arangeDataForDefaultPdfExport(array $data) : array { [$rows, $totalHours, $totalPrice] = [[], 0, 0]; $projectsConfig = $this->configurationService->get('projects'); @@ -114,7 +114,7 @@ class CsvReport implements CsvReportInterface $rows[] = [ 'Gesamt netto', number_format($totalHours, 2, ',', '.'), - NULL, + null, number_format($totalPrice, 2, ',', '.'), ]; $rows[] = [null, null, 'Gessamt brutto', number_format($totalPrice, 2, ',', '.')]; @@ -122,7 +122,7 @@ class CsvReport implements CsvReportInterface return $rows; } - protected function dummyConfig(): array + protected function dummyConfig() : array { return [ 'projects' => [ @@ -132,7 +132,7 @@ class CsvReport implements CsvReportInterface 'price' => 26, // optional specify columns ], - 'TNP' => [ + 'TNP' => [ 'name' => 'Triglav National Park', 'pattern' => 'TNP-[0-9]+', 'price' => 26, diff --git a/app/src/Utils/CsvReport/CsvReportInterface.php b/app/src/Utils/CsvReport/CsvReportInterface.php index 59770c4..eafc9c0 100644 --- a/app/src/Utils/CsvReport/CsvReportInterface.php +++ b/app/src/Utils/CsvReport/CsvReportInterface.php @@ -19,7 +19,7 @@ interface CsvReportInterface * * Project key as key and number of hours as value. */ - public function getInvoiceData(string $filePath): array; + public function getInvoiceData(string $filePath) : array; /** * Data for default drunomics pdf export. @@ -27,5 +27,5 @@ interface CsvReportInterface * * Parsed data from csv report. */ - public function arangeDataForDefaultPdfExport(array $data): array; + public function arangeDataForDefaultPdfExport(array $data) : array; } diff --git a/app/src/Utils/CsvReport/ReportCsv.php b/app/src/Utils/CsvReport/ReportCsv.php index 3f9d957..873413c 100644 --- a/app/src/Utils/CsvReport/ReportCsv.php +++ b/app/src/Utils/CsvReport/ReportCsv.php @@ -17,7 +17,6 @@ use function explode; use function fgetcsv; use function fopen; use function implode; -use function is_array; use function is_numeric; use function number_format; use function preg_match; @@ -46,7 +45,7 @@ class ReportCsv implements ReportCsvInterface /** * {@inheritdoc} */ - public function getInvoiceData(string $filePath): array + public function getInvoiceData(string $filePath) : array { $output = []; // @TODO replace with config service. @@ -80,7 +79,7 @@ class ReportCsv implements ReportCsvInterface * * Project key and unit of time spent. */ - protected function parseCsvFile(array $rawData): array + protected function parseCsvFile(array $rawData) : array { $config = $this->configurationService->get('projects'); foreach ($config as $key => $project) { @@ -94,7 +93,7 @@ class ReportCsv implements ReportCsvInterface /** * Input is array of Work elements and expenses. */ - public function generateTable(array $data): array + public function generateTable(array $data) : array { [$rows, $totalHours, $totalPrice, $add_separator] = [[], 0, 0, false]; $projectsConfig = $this->configurationService->get('projects'); @@ -126,12 +125,12 @@ class ReportCsv implements ReportCsvInterface } if ($add_separator) { // @TODO replace separators with constants for normal separating. - $rows[] = null; - $rows[] = [ + $rows[] = null; + $rows[] = [ 'Gesamt netto', number_format($totalHours, 2, ',', '.'), ' ', - number_format($totalPrice, 2, ',', '.') + number_format($totalPrice, 2, ',', '.'), ]; $add_separator = false; } @@ -173,7 +172,7 @@ class ReportCsv implements ReportCsvInterface /** * {@inheritdoc} */ - public function arangeDataForDefaultPdfExport(array $data): array + public function arangeDataForDefaultPdfExport(array $data) : array { $rows = $this->generateTable($data); $header = $this->configurationService->get('export.labels', null); @@ -189,20 +188,20 @@ class ReportCsv implements ReportCsvInterface /** * {@inheritdoc} */ - public function generateReportTable(string $filePath): array + public function generateReportTable(string $filePath) : array { // ticket-id, ticket-name, time-spent $data = $this->parseReportData($filePath); if (empty($data)) { return []; } - $explodeMinus = fn($ticket) => explode('-', $ticket)[0] ?? 'UNKNOWN'; + $explodeMinus = fn($ticket) => explode('-', $ticket)[0] ?? 'UNKNOWN'; [$previous, $time_sum, $project_time, $table, $all_projects] = [ $data[0]['id'], 0, 0, [], - [$explodeMinus($data[0]['id'])] + [$explodeMinus($data[0]['id'])], ]; foreach ($data as $line) { $project = $explodeMinus($line['id']); @@ -234,7 +233,7 @@ class ReportCsv implements ReportCsvInterface /** * {@inheritdoc} */ - protected function parseReportData(string $filePath): array + protected function parseReportData(string $filePath) : array { $output = []; // @TODO replace with config service. diff --git a/app/src/Utils/CsvReport/ReportCsvInterface.php b/app/src/Utils/CsvReport/ReportCsvInterface.php index 2139e11..adc9918 100644 --- a/app/src/Utils/CsvReport/ReportCsvInterface.php +++ b/app/src/Utils/CsvReport/ReportCsvInterface.php @@ -32,14 +32,14 @@ interface ReportCsvInterface * * Project key as key and number of hours as value. */ - public function getInvoiceData(string $filePath): array; + public function getInvoiceData(string $filePath) : array; /** * Returns array of rows created from array of InvoiceElements. * * If row is null, it is meant to be a table separator. */ - public function generateTable(array $data): array; + public function generateTable(array $data) : array; /** * Data for default drunomics pdf export. @@ -47,7 +47,7 @@ interface ReportCsvInterface * * Parsed data from csv report. */ - public function arangeDataForDefaultPdfExport(array $data): array; + public function arangeDataForDefaultPdfExport(array $data) : array; - public function generateReportTable(string $filePath): array; + public function generateReportTable(string $filePath) : array; } diff --git a/app/src/Utils/Mailer/MailerInterface.php b/app/src/Utils/Mailer/MailerInterface.php index 0e204ff..11f9ab0 100644 --- a/app/src/Utils/Mailer/MailerInterface.php +++ b/app/src/Utils/Mailer/MailerInterface.php @@ -7,17 +7,17 @@ namespace RprtCli\Utils\Mailer; /** * Methods for symfony (swift)mailer service. */ -interface MailerInterface { - +interface MailerInterface +{ /** * Recipients for message. * * @param string[] $to */ - public function setRecipients(array $to): void; + public function setRecipients(array $to) : void; /** * Sends default mail. */ - public function sendDefaultMail(string $output): void; + public function sendDefaultMail(string $output) : void; } diff --git a/app/src/Utils/Mailer/MailerService.php b/app/src/Utils/Mailer/MailerService.php index 10a8b2a..939fb32 100644 --- a/app/src/Utils/Mailer/MailerService.php +++ b/app/src/Utils/Mailer/MailerService.php @@ -54,17 +54,17 @@ class MailerService implements MailerInterface $this->pdf = $pdf; } - public function setRecipients(array $to): void + public function setRecipients(array $to) : void { $this->to = $to; } - public function setSubject(string $subject): void + public function setSubject(string $subject) : void { $this->subject = $subject; } - public function setAttachment(string $path): void + public function setAttachment(string $path) : void { // @TODO - add some error handling. $this->attachment = $path; @@ -117,7 +117,7 @@ class MailerService implements MailerInterface return $this->password; } - public function sendMail(string $from, array $to, string $subject, string $text, array $attachment = []): void + public function sendMail(string $from, array $to, string $subject, string $text, array $attachment = []) : void { $email = new Email(); $email->from($from); @@ -155,7 +155,7 @@ class MailerService implements MailerInterface return new Mailer($transport); } - public function sendDefaultMail(string $output): void + public function sendDefaultMail(string $output) : void { $tokens = $this->pdf->gatherTokensForTemplate( $this->getEmailTemplatePath(), @@ -173,7 +173,7 @@ class MailerService implements MailerInterface ); } - public function getDefaultTokens(): array + public function getDefaultTokens() : array { $tokens = []; $date = strtotime('-1 month'); @@ -182,7 +182,7 @@ class MailerService implements MailerInterface return $tokens; } - protected function getEmailTemplatePath(): ?string + protected function getEmailTemplatePath() : ?string { if (! isset($this->templatePath)) { $template_path = $this->config->get('email.template_path', false); @@ -197,7 +197,7 @@ class MailerService implements MailerInterface return $this->templatePath; } - public function setEmailTemplatePath(string $path): void + public function setEmailTemplatePath(string $path) : void { if (file_exists($path)) { $this->templatePath = $path; diff --git a/app/src/Utils/PdfExport/PdfExportInterface.php b/app/src/Utils/PdfExport/PdfExportInterface.php index 2f1b505..1f74f97 100644 --- a/app/src/Utils/PdfExport/PdfExportInterface.php +++ b/app/src/Utils/PdfExport/PdfExportInterface.php @@ -13,9 +13,9 @@ interface PdfExportInterface * Retrieves path to template file either from command option, configuration * or from uer input. */ - public function getTemplatePath(): ?string; + public function getTemplatePath() : ?string; - public function setTemplatePath(string $path): void; + public function setTemplatePath(string $path) : void; /** * Creates html table from parsed csv data. @@ -23,12 +23,12 @@ interface PdfExportInterface * * First line is header. The rest of them is table body. */ - public function parsedDataToHtmlTable(array $data): ?string; + public function parsedDataToHtmlTable(array $data) : ?string; /** * Reads the template file and replaces token values. */ - public function replaceTokensInTemplate(string $template_path, array $tokens): ?string; + public function replaceTokensInTemplate(string $template_path, array $tokens) : ?string; /** * Creates and export file. @@ -38,7 +38,7 @@ interface PdfExportInterface * * True if export was successfull. */ - public function pdfExport(string $html): bool; + public function pdfExport(string $html) : bool; /** * Goes through the whole process of creating a pdf for the invoice. @@ -48,7 +48,7 @@ interface PdfExportInterface * * Path of the pdf file. */ - public function fromDefaultDataToPdf(array $nice_data, array $tokens = []): string; + public function fromDefaultDataToPdf(array $nice_data, array $tokens = []) : string; /** * Sets output file override via command paramater. @@ -56,7 +56,7 @@ interface PdfExportInterface * * Path of the output pdf file ('/tmp/test.pdf'). */ - public function setOutput(string $output): void; + public function setOutput(string $output) : void; // @TODO support multiple templates by adding template id in config. // @TODO implement twig. @@ -80,5 +80,5 @@ interface PdfExportInterface bool $skip_missing, array $runtime_tokens = [], string $config = 'export.token' - ): array; + ) : array; } diff --git a/app/src/Utils/PdfExport/PdfExportService.php b/app/src/Utils/PdfExport/PdfExportService.php index 0707a5e..5769e8a 100644 --- a/app/src/Utils/PdfExport/PdfExportService.php +++ b/app/src/Utils/PdfExport/PdfExportService.php @@ -35,7 +35,7 @@ class PdfExportService implements PdfExportInterface $this->mpdf = $mpdf; } - public function getTemplatePath(): ?string + public function getTemplatePath() : ?string { if (! isset($this->templatePath)) { $template_path = $this->config->get('export.template_path', false); @@ -50,7 +50,7 @@ class PdfExportService implements PdfExportInterface return $this->templatePath; } - public function setTemplatePath(string $path): void + public function setTemplatePath(string $path) : void { if (file_exists($path)) { $this->templatePath = $path; @@ -64,12 +64,12 @@ class PdfExportService implements PdfExportInterface // @TODO would it make sense to allow more per user extending? // @TODO - too much assumptions on data structure. Create a class with // precise data structure and use that to pass the data around. - public function parsedDataToHtmlTable(array $data): ?string + public function parsedDataToHtmlTable(array $data) : ?string { $table = ''; $header = array_shift($data); $classes = ''; - $rows = []; + $rows = []; foreach ($header as $index => $cell) { $table .= ""; } @@ -106,7 +106,7 @@ class PdfExportService implements PdfExportInterface return $table; } - public function replaceTokensInTemplate(string $template_path, array $tokens): ?string + public function replaceTokensInTemplate(string $template_path, array $tokens) : ?string { $template = file_get_contents($template_path); foreach ($tokens as $key => $value) { @@ -116,7 +116,7 @@ class PdfExportService implements PdfExportInterface } // @TODO write a method to gather tokens. - public function getTokensInTemplate(string $template): array + public function getTokensInTemplate(string $template) : array { // @TODO find substrings of type [[key]] preg_match_all('/\[\[([a-z0-9-_]+)\]\]/', $template, $match); @@ -144,7 +144,7 @@ class PdfExportService implements PdfExportInterface bool $skip_missing = false, array $runtime_tokens = [], string $config = 'export.tokens' - ): array { + ) : array { [$tokens, $missing] = [[], []]; $token_keys = $this->getTokensInTemplate(file_get_contents($template_path)); $config_tokens = $this->config->get($config); @@ -162,7 +162,7 @@ class PdfExportService implements PdfExportInterface return $tokens; } - public function pdfExport(string $html, $output = null): bool + public function pdfExport(string $html, $output = null) : bool { $this->mpdf->SetProtection(['print']); // @TODO make configurable. @@ -187,12 +187,12 @@ class PdfExportService implements PdfExportInterface return $output; } - public function setOutput(string $path): void + public function setOutput(string $path) : void { $this->output = $path; } - public function fromDefaultDataToPdf(array $data, array $tokens = []): string + public function fromDefaultDataToPdf(array $data, array $tokens = []) : string { $template_path = $this->getTemplatePath(); $tokens = $this->defaultTokens(); @@ -209,7 +209,7 @@ class PdfExportService implements PdfExportInterface /** * Get default tokens. */ - protected function defaultTokens(): array + protected function defaultTokens() : array { $tokens = []; $tokens['today'] = date('j. m. y'); diff --git a/app/src/Utils/TimeTrackingServices/YoutrackInterface.php b/app/src/Utils/TimeTrackingServices/YoutrackInterface.php index cd790aa..cb29e19 100644 --- a/app/src/Utils/TimeTrackingServices/YoutrackInterface.php +++ b/app/src/Utils/TimeTrackingServices/YoutrackInterface.php @@ -9,12 +9,12 @@ interface YoutrackInterface /** * Check if client can sign into youtrack with provided token. */ - public function testYoutrackapi(): ?string; + public function testYoutrackapi() : ?string; /** * Get the id of the report from configuration. */ - public function getReportId(): ?string; + public function getReportId() : ?string; /** * Downloads report and returns file path. @@ -25,7 +25,7 @@ interface YoutrackInterface * * If fetch was unsuccssefull return false, otherwise the file path. */ - public function downloadReport(string $report_id): ?string; + public function downloadReport(string $report_id) : ?string; /** * Get a list of reports. @@ -33,16 +33,16 @@ interface YoutrackInterface * * Array of reports with ids as keys and names as values. */ - public function listReports(): array; + public function listReports() : array; - public function setReportId(string $report_id): void; + public function setReportId(string $report_id) : void; - public function setReportName(?string $report_name = null): void; + public function setReportName(?string $report_name = null) : void; - public function getReportName(): ?string; + public function getReportName() : ?string; /** * Clears cache for youtrack report. */ - public function clearReportCache(string $report_id): int; + public function clearReportCache(string $report_id) : int; } diff --git a/app/src/Utils/TimeTrackingServices/YoutrackService.php b/app/src/Utils/TimeTrackingServices/YoutrackService.php index d333553..ab138dd 100644 --- a/app/src/Utils/TimeTrackingServices/YoutrackService.php +++ b/app/src/Utils/TimeTrackingServices/YoutrackService.php @@ -44,7 +44,7 @@ class YoutrackService implements YoutrackInterface $this->httpClient = $http_client; } - public function testYoutrackapi(): ?string + public function testYoutrackapi() : ?string { // Get base url from config or add input. // Get token or add input. @@ -88,7 +88,7 @@ class YoutrackService implements YoutrackInterface ]; } - public function getReportId(): ?string + public function getReportId() : ?string { // --report option value should take precedence. // @TODO error handling. @@ -102,12 +102,12 @@ class YoutrackService implements YoutrackInterface return $yt_report_id; } - public function setReportId(string $report_id): void + public function setReportId(string $report_id) : void { $this->report_id = $report_id; } - public function setReportName(?string $report_name = null): void + public function setReportName(?string $report_name = null) : void { if (! $report_name) { $reports = $this->listReports(); @@ -120,12 +120,12 @@ class YoutrackService implements YoutrackInterface $this->reportName = $report_name; } - public function getReportName(): ?string + public function getReportName() : ?string { return $this->reportName; } - public function downloadReport(string $report_id): ?string + public function downloadReport(string $report_id) : ?string { $path = "youtrack/api/reports/$report_id/export/csv"; $query = ['$top' => -1]; @@ -161,7 +161,7 @@ class YoutrackService implements YoutrackInterface throw new Exception("Unable to download report {$report_id}!"); } - protected function getYtToken(): string + protected function getYtToken() : string { if (isset($this->ytToken)) { return $this->ytToken; @@ -173,12 +173,12 @@ class YoutrackService implements YoutrackInterface return $yt_token; } - public function setYtToken(string $token): void + public function setYtToken(string $token) : void { $this->ytToken = $token; } - protected function getYtUrl(string $path = ''): ?string + protected function getYtUrl(string $path = '') : ?string { if (isset($this->ytBaseUrl)) { $yt_base_url = $this->ytBaseUrl; @@ -199,7 +199,7 @@ class YoutrackService implements YoutrackInterface $this->ytBaseUrl = $base_url; } - public function listReports(): array + public function listReports() : array { // Now filter results by own = true; $url = '/youtrack/api/reports'; @@ -218,11 +218,11 @@ class YoutrackService implements YoutrackInterface return $reports; } - public function clearReportCache(string $report_id): int + public function clearReportCache(string $report_id) : int { $path = "/youtrack/api/reports/${report_id}/status"; $query = [ - '$top' => -1, + '$top' => -1, // phpcs:ignore 'fields' => 'calculationInProgress,error(id),errorMessage,isOutdated,lastCalculated,progress,wikifiedErrorMessage', ]; diff --git a/app/tests/Kernel/ReportCommandTest.php b/app/tests/Kernel/ReportCommandTest.php index fcedf53..c9ee2ed 100644 --- a/app/tests/Kernel/ReportCommandTest.php +++ b/app/tests/Kernel/ReportCommandTest.php @@ -4,12 +4,15 @@ declare(strict_types=1); namespace RprtCli\Tests\Kernel; -use PHPUnit\Framework\TestCase; -use Symfony\Component\Console\Application; -use Symfony\Component\Console\Tester\CommandTester; use DI\ContainerBuilder; +use PHPUnit\Framework\TestCase; use RprtCli\Commands\InvoiceCommand; use RprtCli\Commands\ReportCommand; +use Symfony\Component\Console\Application; +use Symfony\Component\Console\Tester\CommandTester; + +use function file_exists; +use function unlink; /** * Report and invoice command test. @@ -17,8 +20,8 @@ use RprtCli\Commands\ReportCommand; * Does not cover the part of talking to the api, nor does it yet cover email * and pdf generation. @TODO */ -class ReportCommandTest extends TestCase { - +class ReportCommandTest extends TestCase +{ protected const INPUT_CSV_FILE = __DIR__ . '/../data/21-03.csv'; protected const REPORT_OUTPUT_FILE = __DIR__ . '/../data/report-21-03.txt'; @@ -30,7 +33,8 @@ class ReportCommandTest extends TestCase { /** * Run report and invoice command with file option parameter. Check if pdf was generated. */ - public function testExecute() { + public function testExecute() + { $builder = new ContainerBuilder(); $builder->addDefinitions(__DIR__ . '/../test-dependencies.php'); $container = $builder->build(); @@ -42,8 +46,7 @@ class ReportCommandTest extends TestCase { $reportCommand = $container->get(ReportCommand::class); $application->add($reportCommand); - - $reportCommand = $application->find('report'); + $reportCommand = $application->find('report'); $reportCommandTester = new CommandTester($reportCommand); $reportCommandTester->execute([ // pass arguments to the helper @@ -66,11 +69,11 @@ class ReportCommandTest extends TestCase { if (file_exists(self::INVOICE_OUTPUT_PDF)) { unlink(self::INVOICE_OUTPUT_PDF); } - $invoiceCommand = $application->find('invoice'); + $invoiceCommand = $application->find('invoice'); $invoiceCommandTester = new CommandTester($invoiceCommand); $invoiceCommandTester->execute([ - '--file' => self::INPUT_CSV_FILE, - '--pdf' => TRUE, + '--file' => self::INPUT_CSV_FILE, + '--pdf' => true, '--output' => self::INVOICE_OUTPUT_PDF, ]); @@ -83,5 +86,4 @@ class ReportCommandTest extends TestCase { $this->assertStringEqualsFile(self::INVOICE_OUTPUT_FILE, $invoice_output); $this->assertFileExists(self::INVOICE_OUTPUT_PDF); } - } diff --git a/app/tests/test-dependencies.php b/app/tests/test-dependencies.php index 8424b58..1697d6a 100644 --- a/app/tests/test-dependencies.php +++ b/app/tests/test-dependencies.php @@ -1,6 +1,8 @@
{$cell}