Skip to content

Commit

Permalink
PathRoutingParser - check if the file is a symlink that might be in a…
Browse files Browse the repository at this point in the history
…nalysed paths

See phpstan/phpstan#11362
  • Loading branch information
ondrejmirtes committed Jul 23, 2024
1 parent 101467d commit c9a6d2e
Show file tree
Hide file tree
Showing 12 changed files with 367 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ jobs:
cd e2e/baseline-uninit-prop-trait
../../bin/phpstan analyse --configuration test-no-baseline.neon --generate-baseline test-baseline.neon
../../bin/phpstan analyse --configuration test.neon
- script: |
cd e2e/discussion-11362
composer install
../../bin/phpstan
steps:
- name: "Checkout"
Expand Down
1 change: 1 addition & 0 deletions e2e/discussion-11362/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor
24 changes: 24 additions & 0 deletions e2e/discussion-11362/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"config": {
"preferred-install": {
"*": "dist",
"repro/*": "source"
},
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true,
"repositories": [
{
"type": "path",
"url": "./packages/*/"
}
],
"require": {
"repro/site": "@dev",
"php": "^8.1"
},
"require-dev": {
"phpstan/phpstan": "1.11.7"
}
}
103 changes: 103 additions & 0 deletions e2e/discussion-11362/composer.lock

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace Repro\Site\Domain\Model;

class ContentPage
{
public const CONTENT_PAGE_TYPE_CONTENT_ELEMENTS = 'content-elements';

public const CONTENT_PAGE_TYPE_KARAOKE_PLAYER = 'karaoke-player';

protected ?Issue $parentIssue = null;

protected ?Lesson $parentLesson = null;

protected string $title;

protected string $type;

protected bool $navigationVisible;

protected string $navigationColor;

public function __construct()
{
}

public function getParentIssue(): ?Issue
{
return $this->parentIssue;
}

public function getParentLesson(): ?Lesson
{
return $this->parentLesson;
}

public function getTitle(): string
{
return $this->title;
}

public function getType(): string
{
return $this->type;
}

public function getNavigationVisible(): bool
{
return $this->navigationVisible;
}

public function getNavigationColor(): string
{
return $this->navigationColor;
}
}

45 changes: 45 additions & 0 deletions e2e/discussion-11362/packages/site/Classes/Domain/Model/Issue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace Repro\Site\Domain\Model;

use DateTime;

class Issue
{
protected array $settings;

protected ?SchoolYear $parentSchoolYear = null;

protected string $title;

protected int $startDate;

protected string $holidayTitle;


public function __construct()
{
}

public function getParentSchoolYear(): SchoolYear
{
return $this->parentSchoolYear;
}

public function getTitle(): string
{
return $this->title;
}

public function getStartDate(): int
{
return $this->startDate;
}

public function getHolidayTitle(): string
{
return $this->holidayTitle;
}
}
29 changes: 29 additions & 0 deletions e2e/discussion-11362/packages/site/Classes/Domain/Model/Lesson.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Repro\Site\Domain\Model;

class Lesson
{
protected ?SchoolLevel $schoolLevel = null;

protected ?Issue $parentIssue = null;

protected int $lessonNumber;

public function getSchoolLevel(): ?SchoolLevel
{
return $this->schoolLevel;
}

public function getParentIssue(): ?Issue
{
return $this->parentIssue;
}

public function getLessonNumber(): int
{
return $this->lessonNumber;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Repro\Site\Domain\Model;

class SchoolLevel
{
protected string $title;

public function getTitle(): string
{
return $this->title;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace Repro\Site\Domain\Model;

class SchoolYear
{
protected int $startDate;

protected int $endDate;

protected int $introStartDate;

protected int $introEndDate;

public function __construct()
{
}

public function getStartDate(): int
{
return $this->startDate;
}

public function getEndDate(): int
{
return $this->endDate;
}

public function getIntroStartDate(): int
{
return $this->introStartDate;
}

public function getIntroEndDate(): int
{
return $this->introEndDate;
}
}
11 changes: 11 additions & 0 deletions e2e/discussion-11362/packages/site/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"autoload": {
"psr-4": {
"Repro\\Site\\": "Classes"
}
},
"name": "repro/site",
"require": {
"php": "^8.1"
}
}
11 changes: 11 additions & 0 deletions e2e/discussion-11362/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
parameters:
excludePaths:
analyseAndScan:
- .git
analyse:
- vendor

level: 1

paths:
- .
25 changes: 25 additions & 0 deletions src/Parser/PathRoutingParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@

use PHPStan\File\FileHelper;
use function array_fill_keys;
use function array_slice;
use function count;
use function explode;
use function implode;
use function is_link;
use function realpath;
use function str_contains;
use const DIRECTORY_SEPARATOR;

class PathRoutingParser implements Parser
{
Expand Down Expand Up @@ -41,6 +48,24 @@ public function parseFile(string $file): array

$file = $this->fileHelper->normalizePath($file);
if (!isset($this->analysedFiles[$file])) {
// check symlinked file that still might be in analysedFiles
$pathParts = explode(DIRECTORY_SEPARATOR, $file);
for ($i = count($pathParts); $i > 1; $i--) {
$joinedPartOfPath = implode(DIRECTORY_SEPARATOR, array_slice($pathParts, 0, $i));
if (!@is_link($joinedPartOfPath)) {
continue;
}

$realFilePath = realpath($file);
if ($realFilePath !== false) {
$normalizedRealFilePath = $this->fileHelper->normalizePath($realFilePath);
if (isset($this->analysedFiles[$normalizedRealFilePath])) {
return $this->currentPhpVersionRichParser->parseFile($file);
}
}
break;
}

return $this->currentPhpVersionSimpleParser->parseFile($file);
}

Expand Down

0 comments on commit c9a6d2e

Please sign in to comment.