Skip to content

Commit

Permalink
♻ use php 8 features (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
hackhero920 committed Apr 5, 2022
1 parent 1b74e14 commit 7d9acc5
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 57 deletions.
7 changes: 0 additions & 7 deletions .github/dependabot.yml
Expand Up @@ -7,10 +7,3 @@ updates:
time: "08:00"
timezone: US/Central
open-pull-requests-limit: 10
ignore:
- dependency-name: spatie/temporary-directory
versions:
- 2.0.0
- dependency-name: league/flysystem
versions:
- 2.0.0
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Expand Up @@ -16,7 +16,7 @@ jobs:
if: "!contains(github.event.head_commit.message, '[ci skip]')"
strategy:
matrix:
php: ["8.0"]
php: ['8.0', '8.1']

steps:
- name: Checkout the project
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/release.yml
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.3', '7.4', '8.0']
php-versions: ['8.0', '8.1']

steps:
- name: Checkout
Expand All @@ -23,9 +23,6 @@ jobs:
coverage: xdebug
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Remove incompatible dependencies
run: composer remove pestphp/pest pestphp/pest-plugin-mock spatie/pest-plugin-snapshots --dev --no-interaction
if: matrix.php < 8
- name: Install Composer dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader --no-dev --no-interaction
- name: Cleanup unnecessary files
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -69,7 +69,7 @@
"phpcompatibility/php-compatibility": "^9.3",
"roave/security-advisories": "dev-master",
"spatie/pest-plugin-snapshots": "^1.0",
"spatie/temporary-directory": "^1.3",
"spatie/temporary-directory": "^2.0",
"squizlabs/php_codesniffer": "^3.5",
"tmarsteel/mockery-callable-mock": "^2.1",
"wp-cli/wp-cli": "^2.5"
Expand Down
6 changes: 3 additions & 3 deletions phpcs.xml.dist
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<ruleset name="Acorn">
<description>PSR12 with PHP 7.2+ compatibility</description>
<description>PSR12 with PHP 8.0+ compatibility</description>
<arg name="extensions" value="php"/>
<arg name="colors"/>
<arg value="sp"/>
Expand All @@ -12,8 +12,8 @@
<exclude-pattern>src/Illuminate/*</exclude-pattern>
</rule>

<!-- Support for PHP 7.3+ -->
<config name="testVersion" value="7.3-"/>
<!-- Support for PHP 8.0+ -->
<config name="testVersion" value="8.0-"/>

<file>acorn.php</file>
<file>src/Roots</file>
Expand Down
57 changes: 17 additions & 40 deletions src/Roots/Acorn/Bootloader.php
Expand Up @@ -57,11 +57,7 @@ public static function setInstance(?self $bootloader)
*/
public static function getInstance(?ApplicationContract $app = null)
{
if (static::$instance) {
return static::$instance;
}

return static::$instance = new static($app);
return static::$instance ??= new static($app);
}

/**
Expand All @@ -73,9 +69,7 @@ public function __construct(?ApplicationContract $app = null)
{
$this->app = $app;

if (! static::$instance) {
static::$instance = $this;
}
static::$instance ??= $this;
}

/**
Expand Down Expand Up @@ -232,9 +226,7 @@ protected function bootWordPress(ApplicationContract $app)
*/
public function getApplication(): ApplicationContract
{
if (! $this->app) {
$this->app = new Application($this->basePath(), $this->usePaths());
}
$this->app ??= new Application($this->basePath(), $this->usePaths());

$this->app->singleton(
\Illuminate\Contracts\Http\Kernel::class,
Expand Down Expand Up @@ -273,27 +265,19 @@ protected function basePath(): string
return $this->basePath;
}

if (isset($_ENV['APP_BASE_PATH'])) {
return $this->basePath = $_ENV['APP_BASE_PATH'];
}
return $this->basePath = match (true) {
isset($_ENV['APP_BASE_PATH']) => $_ENV['APP_BASE_PATH'],

if (defined('ACORN_BASEPATH')) {
return $this->basePath = constant('ACORN_BASEPATH');
}
defined('ACORN_BASEPATH') => constant('ACORN_BASEPATH'),

if (is_file($composer_path = get_theme_file_path('composer.json'))) {
return $this->basePath = dirname($composer_path);
}
is_file($composer_path = get_theme_file_path('composer.json')) => dirname($composer_path),

if (is_dir($app_path = get_theme_file_path('app'))) {
return $this->basePath = dirname($app_path);
}
is_dir($app_path = get_theme_file_path('app')) => dirname($app_path),

if ($vendor_path = (new Filesystem())->closest(dirname(__DIR__, 4), 'composer.json')) {
return $this->basePath = dirname($vendor_path);
}
$vendor_path = (new Filesystem())->closest(dirname(__DIR__, 4), 'composer.json') => dirname($vendor_path),

return $this->basePath = dirname(__DIR__, 3);
default => dirname(__DIR__, 3)
};
}

/**
Expand Down Expand Up @@ -383,19 +367,12 @@ protected function findPath($path): string
*/
protected function fallbackPath(string $path): string
{
if ($path === 'storage') {
return $this->fallbackStoragePath();
}

if ($path === 'app') {
return $this->basePath() . DIRECTORY_SEPARATOR . 'app';
}

if ($path === 'public') {
return $this->basePath() . DIRECTORY_SEPARATOR . 'public';
}

return dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . $path;
return match ($path) {
'storage' => $this->fallbackStoragePath(),
'app' => $this->basePath() . DIRECTORY_SEPARATOR . 'app',
'public' => $this->basePath() . DIRECTORY_SEPARATOR . 'public',
default => dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . $path,
};
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Roots/Acorn/Kernel.php
Expand Up @@ -2,6 +2,7 @@

namespace Roots\Acorn;

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Http\Kernel as KernelContract;

class Kernel implements KernelContract
Expand Down
2 changes: 1 addition & 1 deletion src/Roots/Acorn/PackageManifest.php
Expand Up @@ -2,8 +2,8 @@

namespace Roots\Acorn;

use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Exception;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Foundation\PackageManifest as FoundationPackageManifest;

Expand Down

0 comments on commit 7d9acc5

Please sign in to comment.