Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,83 @@ jobs:
- name: Run Laravel Pint
run: php vendor/bin/pint --test

phpstan:
name: PHPStan Static Analysis
runs-on: ubuntu-latest
needs: install-composer-dependencies

steps:
- name: Checkout code
uses: actions/checkout@v7

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.5
extensions: mbstring, ctype, fileinfo, json, openssl, pdo, simplexml, sodium, tokenizer, xml

- name: Download vendor directory
uses: actions/download-artifact@v8
with:
name: vendor
path: vendor

- name: Copy .env
run: cp .env.example .env

- name: Generate key
run: php artisan key:generate

- name: Run PHPStan
run: php vendor/bin/phpstan analyse --no-progress --error-format=github --memory-limit=2G

mutation-test:
name: Mutation Tests (Infection, changed lines only)
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
needs: install-composer-dependencies

steps:
- name: Checkout code
uses: actions/checkout@v7
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.5
extensions: mbstring, ctype, exif, fileinfo, gd, json, openssl, pdo, simplexml, sodium, tokenizer, xml
coverage: xdebug

- name: Download vendor directory
uses: actions/download-artifact@v8
with:
name: vendor
path: vendor

- name: Copy .env
run: cp .env.example .env

- name: Generate key
run: php artisan key:generate

- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache

- name: Run Infection on changed lines
env:
# in-memory database so parallel infection threads don't share a sqlite file
DB_CONNECTION: sqlite
DB_DATABASE: ':memory:'
run: >
php -d memory_limit=2G vendor/bin/infection
--git-diff-lines
--git-diff-base=origin/${{ github.base_ref }}
--threads=max
--no-progress
--logger-github

migration-test-sqlite:
name: Migration Test (SQLite)
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ lang/php_*.json
*.sqlite
/storage/operator-mapping.csv
/storage/operator-operators.csv

# Infection
infection.log
5 changes: 3 additions & 2 deletions app/DataProviders/Repositories/MotisLicenseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use App\Models\MotisSourceLicense;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Log;
use JetBrains\PhpStorm\ArrayShape;

class MotisLicenseRepository
{
Expand Down Expand Up @@ -40,7 +39,9 @@ public function getLicense(string $gtfsSource, DataProvider $source): ?MotisSour
return $query?->first();
}

#[ArrayShape(['country' => 'string', 'name' => 'string'])]
/**
* @return array{country: string, name: string}
*/
public function getCountryAndLicense(string $source): array
{
$matches = [];
Expand Down
79 changes: 21 additions & 58 deletions app/Dto/Transport/Station.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,60 +51,24 @@ class Station
)]
public readonly ?array $identifiers;

public function setId(int $id): self
{
private function __construct(
int $id,
?string $uuid,
string $name,
float $latitude,
float $longitude,
?array $identifiers,
?int $ibnr,
?string $rilIdentifier,
) {
$this->id = $id;

return $this;
}

public function setUuid(?string $uuid): self
{
$this->uuid = $uuid;

return $this;
}

public function setName(string $name): self
{
$this->name = $name;

return $this;
}

public function setLatitude(float $latitude): self
{
$this->latitude = $latitude;

return $this;
}

public function setLongitude(float $longitude): self
{
$this->longitude = $longitude;

return $this;
}

public function setIbnr(?int $ibnr): self
{
$this->identifiers = $identifiers;
$this->ibnr = $ibnr;

return $this;
}

public function setRilIdentifier(?string $rilIdentifier): self
{
$this->rilIdentifier = $rilIdentifier;

return $this;
}

public function setIdentifiers(?array $identifiers): self
{
$this->identifiers = $identifiers;

return $this;
}

public static function fromModel(\App\Models\Station $station): self
Expand All @@ -113,16 +77,15 @@ public static function fromModel(\App\Models\Station $station): self
? StationIdentifierResource::collection($station->stationIdentifiers)->resolve()
: null;

$dto = new self();
$dto->setId($station->id)
->setUuid($station->uuid)
->setName($station->name)
->setIbnr(null) // TODO: Kann das hier mittelfristig raus? Wo wird das noch über dieses DTO genutzt?
->setLatitude($station->latitude)
->setLongitude($station->longitude)
->setRilIdentifier(null) // TODO: Kann das hier mittelfristig raus? Wo wird das noch über dieses DTO genutzt?
->setIdentifiers($identifiers);

return $dto;
return new self(
id: $station->id,
uuid: $station->uuid,
name: $station->name,
latitude: $station->latitude,
longitude: $station->longitude,
identifiers: $identifiers,
ibnr: null, // TODO: Kann das hier mittelfristig raus? Wo wird das noch über dieses DTO genutzt?
rilIdentifier: null, // TODO: Kann das hier mittelfristig raus? Wo wird das noch über dieses DTO genutzt?
);
}
}
16 changes: 8 additions & 8 deletions app/Dto/Wikidata/WikidataEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@

readonly class WikidataEntity
{
public string $qId;

public array $rawData;
private function __construct(
public string $qId,
public array $rawData,
) {}

/**
* @throws JsonException|ModelNotFoundException|ConnectionException
Expand All @@ -23,8 +24,6 @@ public static function fetch(string $qId): self
if (!str_starts_with($qId, 'Q')) {
throw new \InvalidArgumentException('Invalid QID');
}
$instance = new self();
$instance->qId = $qId;

$json = Http::withUserAgent(config('services.user_agent'))
->get('https://www.wikidata.org/wiki/Special:EntityData/' . $qId . '.json')
Expand All @@ -33,9 +32,10 @@ public static function fetch(string $qId): self
throw new ModelNotFoundException('Entity not found');
}

$instance->rawData = $json['entities'][$qId];

return $instance;
return new self(
qId: $qId,
rawData: $json['entities'][$qId],
);
}

public function getLabel(string $language = 'en'): ?string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use JetBrains\PhpStorm\ArrayShape;

abstract class JsonExportController extends Controller
{
/**
* @return array{meta: array{user: UserResource, from: string, to: string, exportedAt: string}, data: AnonymousResourceCollection}
*
* @throws DataOverflowException
*/
#[ArrayShape([
'meta' => 'array',
'data' => AnonymousResourceCollection::class,
])]
public static function generateExport(User $user, Carbon $timestampFrom, Carbon $timestampTo): array
{
$preparedData = ExportController::getExportableStatuses($user, $timestampFrom, $timestampTo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use App\Enum\TripSource;
use App\Http\Controllers\Controller;
use Carbon\Carbon;
use JetBrains\PhpStorm\Pure;

abstract class PointsCalculationController extends Controller
{
Expand Down Expand Up @@ -45,7 +44,6 @@ public static function calculatePoints(
);
}

#[Pure]
private static function calculatePointsWithReason(
float $base,
float $distance,
Expand Down Expand Up @@ -82,7 +80,6 @@ public static function getPointsByReason(PointReason $pointReason, int $points,
return ceil($points * $factor);
}

#[Pure]
public static function getFactorByReason(PointReason $pointReason): float|int
{
if (in_array($pointReason, self::REDUCED_POINTS)) {
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ class Authenticate extends Middleware
* Get the path the user should be redirected to when they are not authenticated.
*
* @param Request $request
* @return string
* @return string|null
*/
protected function redirectTo($request)
{
if (!$request->expectsJson()) {
return route('login');
}

return null;
}
}
2 changes: 1 addition & 1 deletion app/Jobs/RefreshPolyline.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function dispatch(Trip $trip): PendingDispatch
{
Cache::set(CacheKey::getReroutePolylineJobKey($trip->id), true, now()->addMinutes(5));

return static::newPendingDispatch(new static($trip));
return static::newPendingDispatch(new self($trip));
}

public function handle(ReRoutingService $reRoutingService): void
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
"brianium/paratest": "^7.8",
"fakerphp/faker": "^1.9",
"filp/whoops": "^2.0",
"infection/infection": "^0.35.12",
"larastan/larastan": "^3.0",
"laravel/pint": "^1.27",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^8.8",
Expand All @@ -66,7 +68,8 @@
"sort-packages": true,
"allow-plugins": {
"php-http/discovery": true,
"stephank/composer-plugin-nixify": true
"stephank/composer-plugin-nixify": true,
"infection/extension-installer": true
}
},
"extra": {
Expand Down
Loading
Loading