Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some exceptions from phpstan.neon #2931

Merged
merged 3 commits into from
Jan 19, 2025
Merged
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
45 changes: 0 additions & 45 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ parameters:
- '#Dynamic call to static method (Illuminate\\Database\\Query\\Builder|Illuminate\\Database\\Eloquent\\(Builder|Relations\\.*)|App\\Models\\Builders\\.*|App\\Eloquent\\FixedQueryBuilder|App\\Relations\\.*)(<.*>)?::where(Not)?(Null|In|Between|Exists|Column|Year|Month|Day)?\(\).#'
- '#Dynamic call to static method (Illuminate\\Database\\Query\\Builder|Illuminate\\Database\\Eloquent\\(Builder|Relations\\.*)|App\\Models\\Builders\\.*|App\\Eloquent\\FixedQueryBuilder|App\\Relations\\.*)(<.*>)?::delete\(\)#'
- '#Dynamic call to static method (Illuminate\\Database\\Query\\Builder|Illuminate\\Database\\Eloquent\\(Builder|Relations\\.*)|App\\Models\\Builders\\.*|App\\Eloquent\\FixedQueryBuilder|App\\Relations\\.*)(<.*>)?::without\(\)#'
# - '#Dynamic call to static method (Illuminate\\Database\\Query\\Builder|Illuminate\\Database\\Eloquent\\(Builder|Relations\\.*)|App\\Models\\Builders\\.*|App\\Eloquent\\FixedQueryBuilder|App\\Relations\\.*)(<.*>)?::with\(\)#'
- '#Dynamic call to static method (Illuminate\\Database\\Query\\Builder|Illuminate\\Database\\Eloquent\\(Builder|Relations\\.*)|App\\Models\\Builders\\.*|App\\Eloquent\\FixedQueryBuilder|App\\Relations\\.*)(<.*>)?::count\(\).#'
- '#Dynamic call to static method (Illuminate\\Database\\Query\\Builder|Illuminate\\Database\\Eloquent\\(Builder|Relations\\.*)|App\\Models\\Builders\\.*|App\\Eloquent\\FixedQueryBuilder|App\\Relations\\.*)(<.*>)?::update\(\).#'
- '#Dynamic call to static method (Illuminate\\Database\\Query\\Builder|Illuminate\\Database\\Eloquent\\(Builder|Relations\\.*)|App\\Models\\Builders\\.*|App\\Eloquent\\FixedQueryBuilder|App\\Relations\\.*)(<.*>)?::inRandomOrder\(\).#'
Expand All @@ -50,18 +49,9 @@ parameters:
- '#Dynamic call to static method (Illuminate\\Database\\Query\\Builder|Illuminate\\Database\\Eloquent\\(Builder|Relations\\.*)|App\\Models\\Builders\\.*|App\\Eloquent\\FixedQueryBuilder|App\\Relations\\.*)(<.*>)?::exists\(\).#'
- '#Dynamic call to static method App\\Models\\Builders\\.*::orderByDesc\(\).#'
- '#Dynamic call to static method App\\Models\\Builders\\.*::selectRaw\(\).#'
# - '#Call to an undefined method Illuminate\\Database\\Eloquent\\.*::with(Only)?\(\)#'
# - '#Call to an undefined method App\\Relations\\HasManyPhotosRecursively::whereNotNull\(\)#'
# - '#Call to an undefined method Illuminate\\Database\\Eloquent\\Builder|Illuminate\\Database\\Eloquent\\Relations\\Relation::whereNotNull\(\).#'
- '#Call to protected method asDateTime\(\) of class Illuminate\\Database\\Eloquent\\Model.#'

# Covariance - LSP princinple: https://en.wikipedia.org/wiki/Liskov_substitution_principle
# -
# message: '#Parameter \#1 \$column \(array<string>\|Closure\|Illuminate\\Database\\Query\\Expression\|string\) of method .* should be contravariant with parameter \$column \(array<int\|string, mixed>\|\(Closure.*\)\|\(Closure.*\)\|Illuminate\\Contracts\\Database\\Query\\Expression\|string\) of method .*#'
# paths:
# - app/Eloquent/FixedQueryBuilderTrait.php
# - '#Parameter \#1 \$models .* of method .*::initRelation\(\) should be contravariant with parameter \$models .* of method .*::initRelation\(\)#'
# - '#Parameter \#(1|2) \$(models|albums|photos|results) .* of method .*::(match|addEagerConstraints)\(\) should be contravariant with parameter \$(models|albums|photos|results) .* of method .*::(match|addEagerConstraints)\(\)#'
- '#Parameter .* of method .*::replicate\(\) should be contravariant with parameter .* of method .*::replicate\(\)#'
- '#Parameter .* of method .*::save\(\) should be contravariant with parameter .* of method .*::save\(\)#'
- '#Parameter .* of method .*::newEloquentBuilder\(\) should be contravariant with parameter .* of method Kalnoy\\Nestedset\\Node<.*>::newEloquentBuilder\(\)#'
Expand All @@ -75,23 +65,9 @@ parameters:
- '#Dynamic call to static method Illuminate\\Foundation\\Application::getCachedConfigPath\(\).#'
- '#Dynamic call to static method Illuminate\\Foundation\\Application::getCachedRoutesPath\(\).#'


# - '#Access to an undefined property Laragear\\WebAuthn\\Models\\WebAuthnCredential::\$authenticatable_id#'

# False positive as stub code for PHP has not yet been updated to 2nd parameter, see https://github.com/php/doc-en/issues/1529 and https://www.php.net/imagick.writeimagefile
# - '#Method Imagick::writeImageFile\(\) invoked with 2 parameters, 1 required#'

# Synth
# -
# message: '#Variable property access on .*#'
# paths:
# - app/Livewire/Synth

# -
# message: '#Parameter .* of method App\\Livewire\\Synth\\.* should be contravariant with parameter .* of method Livewire\\Mechanisms\\HandleComponents\\Synthesizers\\Synth::.*#'
# paths:
# - app/Livewire/Synth

# Migrations
-
message: '#Function define is unsafe to use.#'
Expand All @@ -117,26 +93,6 @@ parameters:
message: '#no value type specified in iterable type array.#'
paths:
- tests
# -
# message: '#Dynamic call to static method Illuminate\\Testing\\TestResponse::assert(Forbidden|ViewIs|Unauthorized|Ok|Status)#'
# paths:
# - tests
# -
# message: '#Call to an undefined method Illuminate\\Testing\\TestResponse::(assert)?(SeeLivewire|dispatch|call|Set|Count)#'
# paths:
# - tests
-
message: '#Dynamic call to static method PHPUnit\\Framework\\Assert::assert(Is)?(Not)?(True|False|Equals|Int|Null|Empty|Count)\(\)#'
paths:
- tests
-
message: '#Dynamic call to static method PHPUnit\\Framework\\Assert::assertFile(DoesNot)?Exists?\(\)#'
paths:
- tests
-
message: '#Dynamic call to static method PHPUnit\\Framework\\Assert::assertString(Not)?(Contains|Ends|Starts)(String|With)\(\)#'
paths:
- tests
-
message: '#Dynamic call to static method Symfony\\Component\\HttpFoundation\\Response::get(Content|StatusCode)\(\)#'
paths:
Expand All @@ -149,7 +105,6 @@ parameters:
message: '#Cannot call method .* on Illuminate\\Testing\\PendingCommand\|int.#'
paths:
- tests

-
message: '#Access to private property App\\Models\\Extensions\\SizeVariants::\$(original|small(2x)?|thumb(2x)?|medium(2x)?|placeholder)#'
paths:
Expand Down
2 changes: 1 addition & 1 deletion scripts/delete_legacy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ rm -fr routes/web-admin-v1.php
sed -i "\#^.*login_required_v1#d" ./app/Http/Kernel.php

sed -i '11d;50,56d;60,64d;68,75d' ./app/Providers/RouteServiceProvider.php
sed -i '42d;54d;55d;79d;84,94d;132,135d;136,139d;148,152d;153,156d' phpstan.neon
sed -i '104,111d' phpstan.neon


12 changes: 6 additions & 6 deletions tests/Feature_v1/AlbumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -785,15 +785,15 @@ public function testSetCoverByOwner()

$this->albums_tests->set_cover($albumID, $photoID1);
$coverID = $this->albums_tests->get($albumID)->offsetGet('cover_id');
$this->assertEquals($photoID1, $coverID);
self::assertEquals($photoID1, $coverID);

$this->albums_tests->set_cover($albumID, $photoID2);
$coverID = $this->albums_tests->get($albumID)->offsetGet('cover_id');
$this->assertEquals($photoID2, $coverID);
self::assertEquals($photoID2, $coverID);

$this->albums_tests->set_cover($albumID, null);
$coverID = $this->albums_tests->get($albumID)->offsetGet('cover_id');
$this->assertEquals($initialCoverID, $coverID);
self::assertEquals($initialCoverID, $coverID);

Auth::logout();
Session::flush();
Expand Down Expand Up @@ -847,15 +847,15 @@ public function testSetHeaderByOwner()

$this->albums_tests->set_header($albumID, $photoID1);
$headerID = $this->albums_tests->get($albumID)->offsetGet('header_id');
$this->assertEquals($photoID1, $headerID);
self::assertEquals($photoID1, $headerID);

$this->albums_tests->set_header($albumID, $photoID2);
$headerID = $this->albums_tests->get($albumID)->offsetGet('header_id');
$this->assertEquals($photoID2, $headerID);
self::assertEquals($photoID2, $headerID);

$this->albums_tests->set_header($albumID, null);
$headerID = $this->albums_tests->get($albumID)->offsetGet('header_id');
$this->assertEquals($initialHeaderID, $headerID);
self::assertEquals($initialHeaderID, $headerID);

Auth::logout();
Session::flush();
Expand Down
32 changes: 16 additions & 16 deletions tests/Feature_v1/BasePhotosAddHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public function testPNGUpload(): void
$photo = static::convertJsonToObject($this->photos_tests->upload(
AbstractTestCase::createUploadedFile(TestConstants::SAMPLE_FILE_PNG)
));
$this->assertStringEndsWith('.png', $photo->size_variants->original->url);
self::assertStringEndsWith('.png', $photo->size_variants->original->url);
}

public function testGIFUpload(): void
Expand All @@ -250,7 +250,7 @@ public function testGIFUpload(): void
$photo = static::convertJsonToObject($this->photos_tests->upload(
AbstractTestCase::createUploadedFile(TestConstants::SAMPLE_FILE_GIF)
));
$this->assertStringEndsWith('.gif', $photo->size_variants->original->url);
self::assertStringEndsWith('.gif', $photo->size_variants->original->url);
}

public function testWEBPUpload(): void
Expand All @@ -259,7 +259,7 @@ public function testWEBPUpload(): void
$photo = static::convertJsonToObject($this->photos_tests->upload(
AbstractTestCase::createUploadedFile(TestConstants::SAMPLE_FILE_WEBP)
));
$this->assertStringEndsWith('.webp', $photo->size_variants->original->url);
self::assertStringEndsWith('.webp', $photo->size_variants->original->url);
}

/**
Expand All @@ -281,11 +281,11 @@ public function testAppleLivePhotoUpload1(): void
null,
[200, 201]
));
$this->assertEquals($photo->id, $video->id);
$this->assertEquals('E905E6C6-C747-4805-942F-9904A0281F02', $video->live_photo_content_id);
$this->assertStringEndsWith('.mov', $video->live_photo_url);
$this->assertEquals(pathinfo($video->live_photo_url, PATHINFO_DIRNAME), pathinfo($video->size_variants->original->url, PATHINFO_DIRNAME));
$this->assertEquals(pathinfo($video->live_photo_url, PATHINFO_FILENAME), pathinfo($video->size_variants->original->url, PATHINFO_FILENAME));
self::assertEquals($photo->id, $video->id);
self::assertEquals('E905E6C6-C747-4805-942F-9904A0281F02', $video->live_photo_content_id);
self::assertStringEndsWith('.mov', $video->live_photo_url);
self::assertEquals(pathinfo($video->live_photo_url, PATHINFO_DIRNAME), pathinfo($video->size_variants->original->url, PATHINFO_DIRNAME));
self::assertEquals(pathinfo($video->live_photo_url, PATHINFO_FILENAME), pathinfo($video->size_variants->original->url, PATHINFO_FILENAME));
}

/**
Expand All @@ -307,13 +307,13 @@ public function testAppleLivePhotoUpload2(): void
null,
[200, 201] // associated image to video.
));
$this->assertEquals('E905E6C6-C747-4805-942F-9904A0281F02', $photo->live_photo_content_id);
$this->assertStringEndsWith('.mov', $photo->live_photo_url);
$this->assertEquals(pathinfo($photo->live_photo_url, PATHINFO_DIRNAME), pathinfo($photo->size_variants->original->url, PATHINFO_DIRNAME));
$this->assertEquals(pathinfo($photo->live_photo_url, PATHINFO_FILENAME), pathinfo($photo->size_variants->original->url, PATHINFO_FILENAME));
self::assertEquals('E905E6C6-C747-4805-942F-9904A0281F02', $photo->live_photo_content_id);
self::assertStringEndsWith('.mov', $photo->live_photo_url);
self::assertEquals(pathinfo($photo->live_photo_url, PATHINFO_DIRNAME), pathinfo($photo->size_variants->original->url, PATHINFO_DIRNAME));
self::assertEquals(pathinfo($photo->live_photo_url, PATHINFO_FILENAME), pathinfo($photo->size_variants->original->url, PATHINFO_FILENAME));

// The initially uploaded video should have been deleted
$this->assertEquals(0, DB::table('photos')->where('id', '=', $video->id)->count());
self::assertEquals(0, DB::table('photos')->where('id', '=', $video->id)->count());
}

/**
Expand All @@ -331,9 +331,9 @@ public function testGoogleMotionPhotoUpload(): void
AbstractTestCase::createUploadedFile(TestConstants::SAMPLE_FILE_GMP_IMAGE)
));

$this->assertStringEndsWith('.mov', $photo->live_photo_url);
$this->assertEquals(pathinfo($photo->live_photo_url, PATHINFO_DIRNAME), pathinfo($photo->size_variants->original->url, PATHINFO_DIRNAME));
$this->assertEquals(pathinfo($photo->live_photo_url, PATHINFO_FILENAME), pathinfo($photo->size_variants->original->url, PATHINFO_FILENAME));
self::assertStringEndsWith('.mov', $photo->live_photo_url);
self::assertEquals(pathinfo($photo->live_photo_url, PATHINFO_DIRNAME), pathinfo($photo->size_variants->original->url, PATHINFO_DIRNAME));
self::assertEquals(pathinfo($photo->live_photo_url, PATHINFO_FILENAME), pathinfo($photo->size_variants->original->url, PATHINFO_FILENAME));
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/Feature_v1/CommandFixPermissionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ public function testFixPermissions(): void
$this->artisan(self::COMMAND, ['--dry-run' => 0])->assertSuccessful();

clearstatcache(true);
$this->assertEquals(00664, fileperms($filePath) & 07777);
$this->assertEquals(02775, fileperms($dirPath) & 07777);
self::assertEquals(00664, fileperms($filePath) & 07777);
self::assertEquals(02775, fileperms($dirPath) & 07777);

chmod($filePath, 00777);
chmod($dirPath, 06777);

$this->artisan(self::COMMAND, ['--dry-run' => 0])->assertSuccessful();

clearstatcache(true);
$this->assertEquals(00664, fileperms($filePath) & 07777);
$this->assertEquals(02775, fileperms($dirPath) & 07777);
self::assertEquals(00664, fileperms($filePath) & 07777);
self::assertEquals(02775, fileperms($dirPath) & 07777);
}
}
8 changes: 4 additions & 4 deletions tests/Feature_v1/CommandGenerateThumbsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public function testThumbRecreation(): void
// Get updated photo and check if size variant has been re-created
/** @var \App\Models\Photo $photo2 */
$photo2 = static::convertJsonToObject($this->photos_tests->get($photo1->id));
$this->assertNotNull($photo2->size_variants->small);
$this->assertEquals($photo1->size_variants->small->width, $photo2->size_variants->small->width);
$this->assertEquals($photo1->size_variants->small->height, $photo2->size_variants->small->height);
$this->assertFileExists(public_path($this->dropUrlPrefix($photo2->size_variants->small->url)));
self::assertNotNull($photo2->size_variants->small);
self::assertEquals($photo1->size_variants->small->width, $photo2->size_variants->small->width);
self::assertEquals($photo1->size_variants->small->height, $photo2->size_variants->small->height);
self::assertFileExists(public_path($this->dropUrlPrefix($photo2->size_variants->small->url)));
}
}
14 changes: 7 additions & 7 deletions tests/Feature_v1/CommandGhostbusterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testRemoveOrphanedFiles(): void
$this->dropUrlPrefix($photo->size_variants->thumb2x?->url),
$this->dropUrlPrefix($photo->size_variants->thumb->url),
], [null]);
$this->assertNotEmpty($fileURLs);
self::assertNotEmpty($fileURLs);

// Remove photo and size variants from DB manually; note we must
// not use an API call as this would also remove the files, and we
Expand All @@ -58,7 +58,7 @@ public function testRemoveOrphanedFiles(): void

// Ensure that files are still there
foreach ($fileURLs as $fileURL) {
$this->assertFileExists(public_path($fileURL));
self::assertFileExists(public_path($fileURL));
}

// Ghostbuster, ...
Expand All @@ -69,7 +69,7 @@ public function testRemoveOrphanedFiles(): void

// Ensure that files are gone
foreach ($fileURLs as $fileURL) {
$this->assertFileDoesNotExist(public_path($fileURL));
self::assertFileDoesNotExist(public_path($fileURL));
}
}

Expand All @@ -93,7 +93,7 @@ public function testRemoveZombiePhotos(): void
$this->dropUrlPrefix($photo->size_variants->thumb2x?->url),
$this->dropUrlPrefix($photo->size_variants->thumb->url),
], [null]);
$this->assertNotEmpty($fileURLs);
self::assertNotEmpty($fileURLs);

// Remove original file
\Safe\unlink(public_path($this->dropUrlPrefix($originalFileURL)));
Expand All @@ -106,20 +106,20 @@ public function testRemoveZombiePhotos(): void
->assertSuccessful();

// Ensure that photo, size variants and all other size variants are gone
$this->assertEquals(
self::assertEquals(
0,
DB::table('photos')
->where('id', '=', $photo->id)
->count()
);
$this->assertEquals(
self::assertEquals(
0,
DB::table('size_variants')
->where('photo_id', '=', $photo->id)
->count()
);
foreach ($fileURLs as $fileURL) {
$this->assertFileDoesNotExist(public_path($fileURL));
self::assertFileDoesNotExist(public_path($fileURL));
}
}
}
2 changes: 1 addition & 1 deletion tests/Feature_v1/CommandTakeDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ public function testSetUploadTimeFromFileTime(): void
$file_time = \Safe\filemtime(public_path($this->dropUrlPrefix($photo->size_variants->original->url)));
$carbon = new Carbon($photo->created_at);

$this->assertEquals($file_time, $carbon->getTimestamp());
self::assertEquals($file_time, $carbon->getTimestamp());
}
}
8 changes: 4 additions & 4 deletions tests/Feature_v1/CommandVideoDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public function testThumbRecreation(): void
// Get updated video and check if thumb has been re-created
/** @var \App\Models\Photo $photo2 */
$photo2 = static::convertJsonToObject($this->photos_tests->get($photo1->id));
$this->assertNotNull($photo2->size_variants->thumb);
$this->assertEquals($photo1->size_variants->thumb->width, $photo2->size_variants->thumb->width);
$this->assertEquals($photo1->size_variants->thumb->height, $photo2->size_variants->thumb->height);
$this->assertFileExists(public_path($this->dropUrlPrefix($photo2->size_variants->thumb->url)));
self::assertNotNull($photo2->size_variants->thumb);
self::assertEquals($photo1->size_variants->thumb->width, $photo2->size_variants->thumb->width);
self::assertEquals($photo1->size_variants->thumb->height, $photo2->size_variants->thumb->height);
self::assertFileExists(public_path($this->dropUrlPrefix($photo2->size_variants->thumb->url)));
}
}
2 changes: 1 addition & 1 deletion tests/Feature_v1/InstallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function testInstall(): void
$response->assertViewIs('install.setup-success');

// try to login with newly created admin
$this->assertTrue(Auth::attempt(['username' => 'admin', 'password' => 'password']));
self::assertTrue(Auth::attempt(['username' => 'admin', 'password' => 'password']));
Auth::logout();

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/Feature_v1/PhotosAddHandlerImagickTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public function testAcceptedRawUpload(): void
AbstractTestCase::createUploadedFile(TestConstants::SAMPLE_FILE_TIFF)
));

$this->assertStringEndsWith('.tif', $photo->size_variants->original->url);
$this->assertEquals(TestConstants::MIME_TYPE_IMG_TIFF, $photo->type);
$this->assertNotNull($photo->size_variants->thumb);
self::assertStringEndsWith('.tif', $photo->size_variants->original->url);
self::assertEquals(TestConstants::MIME_TYPE_IMG_TIFF, $photo->type);
self::assertNotNull($photo->size_variants->thumb);
} finally {
static::setAcceptedRawFormats($acceptedRawFormats);
}
Expand Down
Loading
Loading