Skip to content

Commit

Permalink
Added CI PHPStan
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Jan 4, 2024
1 parent a0ad813 commit cc20ee9
Show file tree
Hide file tree
Showing 20 changed files with 203 additions and 110 deletions.
59 changes: 19 additions & 40 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v3

- name: Get Composer Cache Directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Config
run: cp .env.dist .env

Expand All @@ -39,46 +35,29 @@ jobs:

- name: Run ergebnis/composer-normalize
run: composer normalize --dry-run --no-check-lock
# phpstan:
# permissions:
# contents: read # for actions/checkout to fetch code
# name: PHP Static Analysis
# runs-on: ubuntu-latest
# strategy:
# matrix:
# php: [ '8.1', '8.2' ]
# fail-fast: false
# steps:
# - name: Setup PHP
# uses: shivammathur/setup-php@v2
# with:
# php-version: '8.1' # will be overriden by platform.php in composer.json see https://phpstan.org/config-reference#phpversion
# extensions: mbstring, intl, gd, xml, dom, json, fileinfo, curl, zip, iconv, simplexml
# coverage: none # disable coverage to disable xdebug in the action.
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# - uses: actions/checkout@v3
phpstan:
permissions:
contents: read # for actions/checkout to fetch code
name: PHP Static Analysis
runs-on: ubuntu-latest
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# - name: Get Composer Cache Directory
# id: composer-cache
# run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- uses: actions/checkout@v3

# - name: Cache Composer Directory
# uses: actions/cache@v3
# with:
# path: ${{ steps.composer-cache.outputs.dir }}
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
# restore-keys: ${{ runner.os }}-composer-
- name: Config
run: cp .env.dist .env

# - name: Composer Install
# run: |
# composer install --ansi --prefer-dist --no-interaction --no-progress
# rm composer.lock
# composer config platform.php ${{ matrix.php }}
- name: Composer Install
run: composer install --ansi --prefer-dist --no-interaction --no-progress

# - name: Run phpstan
# run: ./vendor/bin/phpstan analyse -c phpstan.neon.dist
- name: Run phpstan
run: ./vendor/bin/phpstan analyse
# phpunit:
# permissions:
# contents: read # for actions/checkout to fetch code
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@
/.php-cs-fixer.php
/.php-cs-fixer.cache
###< friendsofphp/php-cs-fixer ###

###> phpstan/phpstan ###
###< phpstan/phpstan ###
15 changes: 0 additions & 15 deletions bootstrap.php

This file was deleted.

1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"require-dev": {
"ergebnis/composer-normalize": "^2.41",
"friendsofphp/php-cs-fixer": "^3.45",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.5",
"symfony/browser-kit": "~7.0.0",
"symfony/css-selector": "~7.0.0",
Expand Down
64 changes: 63 additions & 1 deletion composer.lock

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

16 changes: 8 additions & 8 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
parameters:
level: 5
bootstrapFiles:
- bootstrap.php
paths:
- src
- public
ignoreErrors:
- '~^Call to an undefined static method Illuminate\\Database\\Capsule\\Manager::.*$~'
level: 6
paths:
- bin/
- config/
- public/
- src/
- tests/
ignoreErrors:
5 changes: 4 additions & 1 deletion src/Controller/DataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@ public function badgeSvg(Request $request): Response
);
}

/**
* @return array{'branch': string, 'percent': float, 'color': string}|null
*/
private function getBadgeData(
Request $request,
bool $hexColor
): ?array {
$branch = $request->query->get('branch', 'develop');
$branch = (string) $request->query->get('branch', 'develop');
$date = $request->query->get('date');
if ($date) {
$date = date('Y-m-d', strtotime($date)) == $date ? $date : null;
Expand Down
4 changes: 4 additions & 0 deletions src/Controller/GraphController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public function parameters(Request $request): JsonResponse

/**
* Format a list of all the parameters to use in all methods
*
* @return array{'periods': array{'type': string, 'name': string, 'values': array<int, array{'name': string, 'value': string}>, 'default': string}, 'versions': array{'type': string, 'name': string, 'values': array<int, array{'name': string, 'value': string}>, 'default': string}}
*/
private function getParameters(): array
{
Expand Down Expand Up @@ -126,6 +128,8 @@ private function getParameters(): array

/**
* Check is the parameter is valid
*
* @param array<int, array{'name': string, 'value': string}> $values
*/
private function isValidParameter(string $parameter, array $values): bool
{
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/HealthCheckController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function check(string $nightlyGCPUrl): JsonResponse
'campaign' => 'functional',
'platform' => 'chromium',
]);
} catch (QueryException $e) {
} catch (\Exception $e) {
$data['database'] = false;
}

Expand Down
6 changes: 5 additions & 1 deletion src/Controller/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ private function checkAuth(Request $request, string $dateFormat): ?JsonResponse
return null;
}

private function insertExecutionSuite(Execution $execution, \stdClass $suite, string $dateFormat, int $parentSuiteId = null)
private function insertExecutionSuite(Execution $execution, \stdClass $suite, string $dateFormat, int $parentSuiteId = null): void
{
$isMocha6 = $dateFormat === self::FORMAT_DATE_MOCHA6;

Expand Down Expand Up @@ -350,6 +350,10 @@ private function sanitize(string $text): string

private function compareReportData(Execution $execution): Execution
{
if (!$execution->getStartDate()) {
return $execution;
}

$executionPrevious = $this->executionRepository->findOneByNightlyBefore(
$execution->getVersion(),
$execution->getPlatform(),
Expand Down
12 changes: 8 additions & 4 deletions src/Controller/ReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public function reports(Request $request): JsonResponse

// merge two arrays in one and sort them by date
usort($reports, function ($dt1, $dt2) {
$tm1 = isset($dt1['start_date']) ? $dt1['start_date'] : $dt1['date'];
$tm2 = isset($dt2['start_date']) ? $dt2['start_date'] : $dt2['date'];
$tm1 = $dt1['start_date'];
$tm2 = $dt2['start_date'];

return ($tm1 < $tm2) ? 1 : (($tm1 > $tm2) ? -1 : 0);
});
Expand All @@ -112,7 +112,9 @@ public function reports(Request $request): JsonResponse
#[Route('/reports/{idReport}', methods: ['GET'])]
public function report(int $idReport, Request $request): JsonResponse
{
$execution = $this->executionRepository->findOneById($idReport);
$execution = $this->executionRepository->findOneBy([
'id' => $idReport,
]);
if (!$execution) {
return new JsonResponse([
'message' => 'Execution not found',
Expand Down Expand Up @@ -156,7 +158,9 @@ public function report(int $idReport, Request $request): JsonResponse
#[Route('/reports/{idReport}/suites/{idSuite}', methods: ['GET'])]
public function reportSuite(int $idReport, int $idSuite, Request $request): JsonResponse
{
$execution = $this->executionRepository->findOneById($idReport);
$execution = $this->executionRepository->findOneBy([
'id' => $idReport,
]);
if (!$execution) {
return new JsonResponse([
'message' => 'Execution not found',
Expand Down
13 changes: 7 additions & 6 deletions src/Entity/Execution.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class Execution
private ?string $filename = null;

#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $start_date = null;
private ?\DateTime $start_date = null;

#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $end_date = null;
private ?\DateTime $end_date = null;

#[ORM\Column]
private ?int $duration = null;
Expand Down Expand Up @@ -73,6 +73,7 @@ class Execution
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private \DateTimeInterface $insertion_end_date;

/** @var Collection<int, Suite> */
#[ORM\OneToMany(mappedBy: 'execution', targetEntity: Suite::class)]
private Collection $suitesCollection;

Expand Down Expand Up @@ -117,24 +118,24 @@ public function setFilename(?string $filename): static
return $this;
}

public function getStartDate(): ?\DateTimeInterface
public function getStartDate(): ?\DateTime
{
return $this->start_date;
}

public function setStartDate(?\DateTimeInterface $start_date): static
public function setStartDate(?\DateTime $start_date): static
{
$this->start_date = $start_date;

return $this;
}

public function getEndDate(): ?\DateTimeInterface
public function getEndDate(): ?\DateTime
{
return $this->end_date;
}

public function setEndDate(?\DateTimeInterface $end_date): static
public function setEndDate(?\DateTime $end_date): static
{
$this->end_date = $end_date;

Expand Down
Loading

0 comments on commit cc20ee9

Please sign in to comment.