Skip to content

Commit

Permalink
perf(music, meting): Mark classes as final for performance
Browse files Browse the repository at this point in the history
- Marked `Music` and `Meting` classes as final to improve performance by preventing further inheritance.
- Added `dg/bypass-finals` dependency to allow testing of final classes.
- Updated PHPUnit configuration to enable bypassing final class restrictions.
  • Loading branch information
guanguans committed Sep 27, 2024
1 parent e1d513b commit cc4a8ae
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/Music.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
use Laravel\Prompts\Progress;
use function Laravel\Prompts\progress;

class Music implements Contracts\HttpClientFactory, Contracts\Music
final class Music implements Contracts\HttpClientFactory, Contracts\Music
{
use HttpClientFactory;
use Macroable;
Expand Down
4 changes: 2 additions & 2 deletions app/Support/Meting.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

namespace App\Support;

class Meting extends \Metowolf\Meting
final class Meting extends \Metowolf\Meting
{
/** @noinspection ClassOverridesFieldOfSuperClassInspection */
protected array $temp = [];

public function __construct($value = 'netease')
public function __construct(string $value = 'netease')
{
parent::__construct($value);
$this->format();
Expand Down
8 changes: 8 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8",
"brainmaestro/composer-git-hooks": "^3.0",
"dg/bypass-finals": "^1.8",
"driftingly/rector-laravel": "^1.2",
"ergebnis/composer-normalize": "^2.43",
"ergebnis/license": "^2.4",
Expand Down Expand Up @@ -105,6 +106,13 @@
"forward-command": true,
"target-directory": "vendor-bin"
},
"cleaner-ignore": {
"ergebnis/composer-normalize": true,
"ergebnis/license": true,
"foo/bar": [
"baz*"
]
},
"hooks": {
"post-merge": [
"composer checks"
Expand Down
65 changes: 59 additions & 6 deletions composer.lock

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

3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@
<file>app/Support/helpers.php</file>
</exclude>
</source>
<!--<extensions>
<bootstrap class="DG\BypassFinals\PHPUnitExtension"/>
</extensions>-->
</phpunit>
11 changes: 11 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,21 @@

use App\Music;
use App\Support\Meting;
use DG\BypassFinals;
use Tests\TestCase;

uses(TestCase::class)
->beforeAll(function (): void {
BypassFinals::enable(bypassReadOnly: false);
BypassFinals::allowPaths([
\dirname(__DIR__).'/app/*',
// '*/app/*',
]);
BypassFinals::denyPaths([
'*/vendor/*',
]);
BypassFinals::setCacheDirectory(__DIR__.'/../build/bypass-finals');

clear_same_namespace();
})
->beforeEach(function (): void {
Expand Down

0 comments on commit cc4a8ae

Please sign in to comment.