Skip to content

Commit

Permalink
Add additional strictness in phpstan (#120)
Browse files Browse the repository at this point in the history
1) Set phpstan rule level to max
2) Fix relevant phpstan violations
3) Generate a baseline and include it in the phpstan configuration
  • Loading branch information
nilmerg authored Aug 31, 2023
2 parents 26da7df + 4a8039c commit bda9ea9
Show file tree
Hide file tree
Showing 7 changed files with 2,060 additions and 33 deletions.
19 changes: 10 additions & 9 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,22 @@ jobs:
tools: phpcs

- name: Setup dependencies
run: composer require -n --no-progress overtrue/phplint
&& git clone --single-branch --branch master https://github.com/Icinga/icingaweb2.git vendor/icingaweb2
&& git clone --single-branch --branch master https://github.com/Icinga/icingadb-web.git vendor/icingadb-web
&& git clone --single-branch --branch master https://github.com/Icinga/icingaweb2-module-director.git vendor/icingaweb2-module-director
&& git clone --single-branch --branch snapshot/nightly https://github.com/Icinga/icinga-php-library.git vendor/icinga-php-library
&& git clone --single-branch --branch snapshot/nightly https://github.com/Icinga/icinga-php-thirdparty.git vendor/icinga-php-thirdparty
run: |
composer require -n --no-progress overtrue/phplint
git clone --depth 1 https://github.com/Icinga/icingaweb2.git vendor/icingaweb2
git clone --depth 1 https://github.com/Icinga/icingadb-web.git vendor/icingadb-web
git clone --depth 1 https://github.com/Icinga/icingaweb2-module-director.git vendor/icingaweb2-module-director
git clone --depth 1 -b snapshot/nightly https://github.com/Icinga/icinga-php-library.git vendor/icinga-php-library
git clone --depth 1 -b snapshot/nightly https://github.com/Icinga/icinga-php-thirdparty.git vendor/icinga-php-thirdparty
- name: PHP Lint
if: success() || matrix.allow_failure
if: ${{ ! cancelled() }}
run: ./vendor/bin/phplint -n --exclude={^vendor/.*} -- .

- name: PHP CodeSniffer
if: success() || matrix.allow_failure
if: ${{ ! cancelled() }}
run: phpcs

- name: PHPStan
if: ${{ ! cancelled() }}
uses: php-actions/phpstan@v3
if: success() || matrix.allow_failure
5 changes: 3 additions & 2 deletions library/Jira/RestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Icinga\Module\Jira;

use CurlHandle;
use Exception;
use Icinga\Application\Benchmark;
use Icinga\Application\Config;
Expand Down Expand Up @@ -574,14 +575,14 @@ protected function getHttpErrorMessage($statusCode)
}

/**
* @return resource
* @return resource|CurlHandle
*/
protected function curl()
{
if ($this->curl === null) {
$this->curl = \curl_init($this->baseUrl);
if (! $this->curl) {
throw new RuntimeException('CURL INIT ERROR: ' . \curl_error($this->curl));
throw new RuntimeException('Failed to initialize cURL session');
}
}

Expand Down
16 changes: 0 additions & 16 deletions library/Jira/Web/RenderingHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,6 @@ public function shortTimeSince($time, $onlyTime = true)
);
}

public function anonymize($test)
{
return $test;

$test = preg_replace_callback(
'/([A-Z]{4})\-(\d{3,4})/',
function ($what) {
return strrev(strtolower($what[1])) . $what[2] . '.example.com';
},
$test
);
$test = preg_replace('/1\d+\.\d+\./', '192.168.', $test);

return $test;
}

protected function api()
{
if ($this->api === null) {
Expand Down
5 changes: 3 additions & 2 deletions library/Jira/Web/Table/IssueDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use ipl\Html\Table;
use ipl\I18n\Translation;
use ipl\Web\Widget\Icon;
use stdClass;

class IssueDetails extends Table
{
Expand Down Expand Up @@ -94,9 +95,9 @@ protected function assemble()

$this->addComments(array_reverse($fields->comment->comments));
$this->addComment(
$helper->anonymize($fields->summary),
$fields->summary,
$fields->created,
$helper->anonymize($fields->description)
$fields->description
);
}

Expand Down
4 changes: 2 additions & 2 deletions library/Jira/Web/Table/IssuesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ protected function assemble()
Html::tag('strong')->add(
new Link($issue->key, Url::fromPath('jira/issue/show', ['key' => $issue->key]))
),
$helper->anonymize($issue->fields->summary),
$issue->fields->summary,
Html::tag(
'p',
$helper->anonymize($issue->fields->description)
$issue->fields->description
),
])->setSeparator(' '),
static::td($helper->shortTimeSince($issue->fields->created)),
Expand Down
Loading

0 comments on commit bda9ea9

Please sign in to comment.