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

Code refactoring #58

Merged
merged 1 commit into from
Sep 10, 2023
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
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
* text=auto
/tests export-ignore
/.github export-ignore
.gitignore export-ignore
.travis.yml export-ignore
phpunit.xml export-ignore
52 changes: 52 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: run-tests

on:
pull_request: null
push:
branches: [ master ]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ ubuntu-latest ]
php: [ 8.0, 8.1, 8.2 ]
stability: [ prefer-stable ]

name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

- name: Validate Composer
run: composer validate

- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Restore Composer Cache
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.stability }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.stability }}-composer

- name: Install Dependencies
uses: nick-invision/[email protected]
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit
14 changes: 8 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@
}
],
"require": {
"php": ">=7.1",
"illuminate/config": "^5.6|^6.0|^7.0|^8.0|^9.0|^10.0",
"illuminate/support": "^5.6|^6.0|^7.0|^8.0|^9.0|^10.0",
"illuminate/contracts": "^5.6|^6.0|^7.0|^8.0|^9.0|^10.0",
"illuminate/console": "^5.6|^6.0|^7.0|^8.0|^9.0|^10.0"
"ext-json": "*",
"php": ">=8.0",
"illuminate/config": "^9.0|^10.0",
"illuminate/support": "^9.0|^10.0",
"illuminate/contracts": "^9.0|^10.0",
"illuminate/console": "^9.0|^10.0"
},
"require-dev": {
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^7.0|^9.3"
"phpunit/phpunit": "^9.3",
"vimeo/psalm": "^5.15"
},
"autoload": {
"psr-4": {
Expand Down
14 changes: 14 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
44 changes: 12 additions & 32 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,11 @@

class InstallCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'meta-tags:install';

/**
* The console command description.
*
* @var string
*/

protected $description = 'Install all of the MetaTags package resources';

/**
* Execute the console command.
*
* @return void
*/
public function handle()
public function handle(): void
{
$this->comment('Publishing MetaTags Service Provider...');
$this->callSilent('vendor:publish', ['--tag' => 'meta-tags-provider']);
Expand All @@ -43,35 +28,34 @@ public function handle()

/**
* Register the Nova service provider in the application configuration file.
*
* @return void
*/
protected function registerServiceProvider()
protected function registerServiceProvider(): void
{
$namespace = Str::replaceLast('\\', '', $this->getLaravel()->getNamespace());

/** @psalm-suppress UndefinedFunction */
$config = file_get_contents(config_path('app.php'));
$line = "{$namespace}\Providers\MetaTagsServiceProvider::class";
$line = $namespace . '\Providers\MetaTagsServiceProvider::class';

if (Str::contains($config, $line)) {
$this->warn('Config config/app.php contains MetaTagsServiceProvider. Registration canceled!');
return;
}

/** @psalm-suppress UndefinedFunction */
file_put_contents(config_path('app.php'), str_replace(
"{$namespace}\\Providers\EventServiceProvider::class,".PHP_EOL,
"{$namespace}\\Providers\EventServiceProvider::class,".PHP_EOL." {$line},".PHP_EOL,
$namespace . '\Providers\EventServiceProvider::class,'.PHP_EOL,
$namespace . '\Providers\EventServiceProvider::class,'.PHP_EOL.sprintf(' %s,', $line).PHP_EOL,
$config
));
}

/**
* Set the proper application namespace on the installed files.
*
* @return void
*/
protected function setAppNamespace()
protected function setAppNamespace(): void
{
/** @psalm-suppress UndefinedFunction */
$this->setAppNamespaceOn(
app_path('Providers/MetaTagsServiceProvider.php'),
$this->getLaravel()->getNamespace()
Expand All @@ -80,17 +64,13 @@ protected function setAppNamespace()

/**
* Set the namespace on the given file.
*
* @param string $file
* @param string $namespace
* @return void
*/
protected function setAppNamespaceOn($file, $namespace)
protected function setAppNamespaceOn(string $file, string $namespace): void
{
file_put_contents($file, str_replace(
'App\\',
$namespace,
file_get_contents($file)
));
}
}
}
7 changes: 1 addition & 6 deletions src/Contracts/MetaTags/Entities/HasVisibilityConditions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@ interface HasVisibilityConditions

/**
* Check if entity should be rendered
*
* @return bool
*/
public function isVisible(): bool;

/**
* Add visibility condition
* @param Closure $condition
*
* @return $this
*/
public function visibleWhen(Closure $condition);
public function visibleWhen(Closure $condition): self;
}
1 change: 0 additions & 1 deletion src/Contracts/MetaTags/Entities/TagInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ interface TagInterface extends Htmlable, Arrayable
{
/**
* Get tag placement (footer, head, ...)
* @return string
*/
public function getPlacement(): string;
}
36 changes: 12 additions & 24 deletions src/Contracts/MetaTags/Entities/TitleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,34 @@ interface TitleInterface extends TagInterface
/**
* Specify max length of the title
*
* @param int $maxLength
*
* @return $this
* @param positive-int $maxLength
*/
public function setMaxLength(int $maxLength);
public function setMaxLength(int $maxLength): self;

/**
* Set the main title
*
* @param string|null $title
* @param int|null $maxLength
*
* @return $this
* @param positive-int|null $maxLength
*/
public function setTitle(?string $title, ?int $maxLength = null);
public function setTitle(?string $title, ?int $maxLength = null): self;

/**
* Prepend next part of title
*
* @param string $text
*
* @return $this
*/
public function prepend(string $text);
public function prepend(string $text): self;

/**
* Toggle RTL mode
*
* @param bool $status
*
* @return $this
*/
public function rtl(bool $status = true);
public function rtl(bool $status = true): self;

/**
* Determine separator among title parts
*
* @param string $separator
*
* @return $this
*/
public function setSeparator(string $separator);
public function setSeparator(string $separator): self;

/**
* Get the title
*/
public function getTitle(): string;
}
10 changes: 1 addition & 9 deletions src/Contracts/MetaTags/GeoMetaInformationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,21 @@ interface GeoMetaInformationInterface
{
/**
* Get the latitude
*
* @return string
*/
public function latitude(): string;

/**
* Get the longitude
*
* @return string
*/
public function longitude(): string;

/**
* Get the Place Name
*
* @return string|null
*/
public function placename(): ?string;

/**
* Get the region
*
* @return string|null
*/
public function region(): ?string;
}
}
Loading
Loading