Skip to content

Commit

Permalink
Merge pull request #33 from frugan-dev/master
Browse files Browse the repository at this point in the history
Code refactoring (maintained support for PHP v7.4)
  • Loading branch information
dbfx authored Feb 5, 2024
2 parents 3a16b7c + 57ccdc3 commit 4576cd8
Show file tree
Hide file tree
Showing 17 changed files with 432 additions and 189 deletions.
69 changes: 69 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Laravel-Strapi helper.
*
* (ɔ) Dave Blakey https://github.com/dbfx
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.md.
*/

use PhpCsFixer\Config;
use PhpCsFixer\ConfigurationException\InvalidConfigurationException;
use PhpCsFixer\Finder;
use PhpCsFixer\FixerFactory;
use PhpCsFixer\RuleSet;

$header = <<<'EOF'
This file is part of the Laravel-Strapi helper.
(ɔ) Dave Blakey https://github.com/dbfx
This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.md.
EOF;

// exclude will work only for directories, so if you need to exclude file, try notPath
// directories passed as exclude() argument must be relative to the ones defined with the in() method
$finder = Finder::create()
->in([__DIR__])
->exclude(['vendor'])
->append([__DIR__.'/.php-cs-fixer.dist.php'])
;

$config = (new Config())
->setCacheFile(sys_get_temp_dir().'/.php_cs.cache')
->setRiskyAllowed(true)
->setRules([
// https://mlocati.github.io/php-cs-fixer-configurator
'@PHP74Migration:risky' => true,
'@PHP74Migration' => true,
'@PhpCsFixer' => true,
// '@PhpCsFixer:risky' => true,
'general_phpdoc_annotation_remove' => ['annotations' => ['expectedDeprecation']],
'header_comment' => ['header' => $header],
])
->setFinder($finder)
;

// special handling of fabbot.io service if it's using too old PHP CS Fixer version
if (false !== getenv('FABBOT_IO')) {
try {
FixerFactory::create()
->registerBuiltInFixers()
->registerCustomFixers($config->getCustomFixers())
->useRuleSet(new RuleSet($config->getRules()))
;
} catch (InvalidConfigurationException $e) {
$config->setRules([]);
} catch (UnexpectedValueException $e) {
$config->setRules([]);
} catch (InvalidArgumentException $e) {
$config->setRules([]);
}
}

return $config;
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ There are several useful options available as well.
- ```$limit``` sets how many items you are requesting
- ```$start``` is the offset to be used with limit, useful for pagination
- ```$populate``` is an array containing the fields to populate
- ```$queryData``` is an array of additional key-value pairs to add to the query string

```php
use Dbfx\LaravelStrapi\LaravelStrapi;

$strapi = new LaravelStrapi();
$blogs = $strapi->collection('blogs', $sortKey = 'id', $sortOrder = 'DESC', $limit = 20, $start = 0, $fullUrls = true, $populate = ['author', 'images']);
$blogs = $strapi->collection('blogs', $sortKey = 'id', $sortOrder = 'DESC', $limit = 20, $start = 0, $fullUrls = true, $populate = ['author', 'images'], $queryData = ['locale' => 'en']);

$entry = $strapi->entry('blogs', 1, $fullUrls = true, $populate = ['author', 'images']);
$entry = $strapi->entry('blogs', 1, $fullUrls = true, $populate = ['author', 'images'], $queryData = ['locale' => 'en']);
```

You may also access Single Type items as follows:
Expand Down
51 changes: 32 additions & 19 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
{
"name": "dbfx/laravel-strapi",
"description": "Laravel wrapper for using the Strapi headless CMS",
"license": "MIT",
"keywords": [
"laravel",
"strapi",
"laravel-strapi",
"strapi-cms",
"laravel-package"
],
"homepage": "https://github.com/dbfx/laravel-strapi",
"license": "MIT",
"authors": [
{
"name": "Dave Blakey",
"email": "[email protected]",
"role": "Developer"
}
],
"homepage": "https://github.com/dbfx/laravel-strapi",
"require": {
"php": "^7.3|^7.4|^8.0|^8.1|^8.2",
"laravel/framework": "^8|^9|^10",
"spatie/laravel-package-tools": "^1.4.3",
"illuminate/contracts": "^8.37|^9.0|^10"
"php": "^7.4 || ^8.0",
"illuminate/contracts": "^8.37 || ^9.0 || ^10",
"laravel/framework": "^8 || ^9 || ^10",
"spatie/laravel-package-tools": "^1.4.3"
},
"require-dev": {
"phpunit/phpunit": "^9.6",
"orchestra/testbench": "^6.0"
"brianium/paratest": "^6.2",
"ergebnis/composer-normalize": "^2.42",
"friendsofphp/php-cs-fixer": "^3.48",
"nunomaduro/collision": "^5.3 || ^6.0",
"orchestra/testbench": "^6.15",
"phpro/grumphp-shim": "^1.13",
"phpunit/phpunit": "^9.3",
"rector/rector": "^0.19.5",
"roave/security-advisories": "dev-latest",
"spatie/laravel-ray": "^1.9",
"vimeo/psalm": "^5.7"
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"Dbfx\\LaravelStrapi\\": "src",
Expand All @@ -38,24 +49,26 @@
"Dbfx\\LaravelStrapi\\Tests\\": "tests"
}
},
"scripts": {
"psalm": "vendor/bin/psalm",
"test": "./vendor/bin/testbench package:test --parallel --no-coverage",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
},
"config": {
"allow-plugins": {
"ergebnis/composer-normalize": true,
"phpro/grumphp-shim": true
},
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"Dbfx\\LaravelStrapi\\LaravelStrapiServiceProvider"
],
"aliases": {
"LaravelStrapi": "Dbfx\\LaravelStrapi\\LaravelStrapiFacade"
}
},
"providers": [
"Dbfx\\LaravelStrapi\\LaravelStrapiServiceProvider"
]
}
},
"minimum-stability": "dev",
"prefer-stable": true
"scripts": {
"psalm": "vendor/bin/psalm",
"test": "./vendor/bin/testbench package:test --parallel --no-coverage",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
}
}
13 changes: 12 additions & 1 deletion config/strapi.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Laravel-Strapi helper.
*
* (ɔ) Dave Blakey https://github.com/dbfx
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.md.
*/

return [
// The url to your Strapi installation, e.g. https://strapi.yoursite.com/
'url' => env('STRAPI_URL'),

// How long to cache results for in seconds
'cacheTime' => env('STRAPI_CACHE_TIME', 3600),
'cacheTime' => (int) env('STRAPI_CACHE_TIME', 3600),

// Token for authentication
'token' => env('STRAPI_TOKEN', null),
Expand Down
23 changes: 23 additions & 0 deletions grumphp.yml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
grumphp:
process_timeout: null
tasks:
composer: ~

composer_normalize: ~

phpcsfixer:
config: .php-cs-fixer.dist.php

#https://www.php.net/supported-versions.php
phpversion:
project: '7.4'

psalm:
config: psalm.xml.dist
show_info: true

#FIXME - upgrade to PHP 8.x
#rector: ~

securitychecker_roave:
run_always: true
56 changes: 37 additions & 19 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" executionOrder="random" failOnWarning="true" failOnRisky="true" failOnEmptyTestSuite="true" beStrictAboutOutputDuringTests="true">
<testsuites>
<testsuite name="Dbfx Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<php>
<env name="STRAPI_URL" value="http://localhost:3000" />
</php>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
verbose="true"
>
<testsuites>
<testsuite name="Dbfx Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
</phpunit>
31 changes: 31 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Laravel-Strapi helper.
*
* (ɔ) Dave Blakey https://github.com/dbfx
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.md.
*/

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;

return RectorConfig::configure()
->withPaths([
__DIR__.'/config',
__DIR__.'/src',
__DIR__.'/tests',
])
->withRules([
InlineConstructorDefaultToPropertyRector::class,
])
->withSets([
// define sets of rules
LevelSetList::UP_TO_PHP_74,
])
;
16 changes: 12 additions & 4 deletions src/Commands/LaravelStrapiCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Laravel-Strapi helper.
*
* (ɔ) Dave Blakey https://github.com/dbfx
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.md.
*/

namespace Dbfx\LaravelStrapi\Commands;

use Illuminate\Console\Command;
Expand All @@ -10,8 +21,5 @@ class LaravelStrapiCommand extends Command

public $description = 'Laravel Strapi Helper';

public function handle()
{
//
}
public function handle(): void {}
}
17 changes: 12 additions & 5 deletions src/Exceptions/NotFound.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<?php

namespace Dbfx\LaravelStrapi\Exceptions;
declare(strict_types=1);

/*
* This file is part of the Laravel-Strapi helper.
*
* (ɔ) Dave Blakey https://github.com/dbfx
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.md.
*/

use RuntimeException;
namespace Dbfx\LaravelStrapi\Exceptions;

class NotFound extends RuntimeException
{
}
class NotFound extends \RuntimeException {}
17 changes: 12 additions & 5 deletions src/Exceptions/PermissionDenied.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<?php

namespace Dbfx\LaravelStrapi\Exceptions;
declare(strict_types=1);

/*
* This file is part of the Laravel-Strapi helper.
*
* (ɔ) Dave Blakey https://github.com/dbfx
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.md.
*/

use RuntimeException;
namespace Dbfx\LaravelStrapi\Exceptions;

class PermissionDenied extends RuntimeException
{
}
class PermissionDenied extends \RuntimeException {}
Loading

0 comments on commit 4576cd8

Please sign in to comment.