Skip to content

Commit

Permalink
Merge branch 'main' of github.com:spatie/error-solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Jun 26, 2024
2 parents 09be7d6 + 830a2f7 commit 9782ba6
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 33 deletions.
31 changes: 19 additions & 12 deletions .github/workflows/fix-php-code-style-issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,27 @@ permissions:
contents: write

jobs:
php-code-styling:
style:
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Checkout code
uses: actions/checkout@v4

- name: Fix PHP code style issues
uses: aglipanci/laravel-pint-action@2.4
- name: Fix style
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php_cs.php --allow-risky=yes

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Fix styling
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Fix styling
branch: ${{ steps.extract_branch.outputs.branch }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35 changes: 35 additions & 0 deletions .php_cs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

$finder = Symfony\Component\Finder\Finder::create()
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

return (new PhpCsFixer\Config())
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline' => true,
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
'binary_operator_spaces' => true,
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
],
'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true,
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
],
'single_trait_insert_per_statement' => true,
])
->setFinder($finder);
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

All notable changes to `error-solutions` will be documented in this file.

## 1.0.1 - 2024-06-21

- Add the legacy string comperator

**Full Changelog**: https://github.com/spatie/error-solutions/compare/1.0.0...1.0.1

## 1.0.0 - 2024-06-12

- Initial release

**Full Changelog**: https://github.com/spatie/error-solutions/compare/0.0.1...1.0.0

## 0.0.1 - 2024-06-11

**Full Changelog**: https://github.com/spatie/error-solutions/commits/0.0.1
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"illuminate/broadcasting" : "^10.0|^11.0",
"openai-php/client": "^0.10.1",
"illuminate/cache" : "^10.0|^11.0",
"laravel/pint" : "^1.0",
"pestphp/pest" : "^2.20",
"phpstan/phpstan" : "^1.11",
"psr/simple-cache-implementation" : "^3.0",
Expand Down
10 changes: 10 additions & 0 deletions legacy/laravel-ignition/Support/StringComparator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Spatie\LaravelIgnition\Support;

use Spatie\ErrorSolutions\Support\Laravel\StringComparator as BaseStringComparator;

class StringComparator extends BaseStringComparator
{

}
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ parameters:
count: 1
path: src/Contracts/SolutionProviderRepository.php

-
message: "#^Method Spatie\\\\ErrorSolutions\\\\DiscoverSolutionProviders\\:\\:getProviderClassesForType\\(\\) should return array\\<Spatie\\\\ErrorSolutions\\\\Contracts\\\\HasSolutionsForThrowable\\> but returns array\\<int, string\\>\\.$#"
count: 1
path: src/DiscoverSolutionProviders.php

-
message: "#^Unable to resolve the template type TKey in call to function collect$#"
count: 1
Expand Down
14 changes: 10 additions & 4 deletions src/DiscoverSolutionProviders.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@

class DiscoverSolutionProviders
{
/** @var array<string, string> */
protected array $config = [
'ai' => 'SolutionProviders/OpenAi',
'php' => 'SolutionProviders',
'laravel' => 'SolutionProviders/Laravel'
'laravel' => 'SolutionProviders/Laravel',
];

/** @return array<HasSolutionsForThrowable */
/**
* @param array<string> $types
*
* @return array<HasSolutionsForThrowable>
*/
public static function for(array $types): array
{
if (in_array('php', $types)) {
Expand All @@ -30,7 +35,7 @@ public function __construct(protected array $types)

}

/** @return array<HasSolutionsForThrowable */
/** @return array<HasSolutionsForThrowable> */
public function get(): array
{
$providers = [];
Expand All @@ -42,6 +47,7 @@ public function get(): array
return $providers;
}

/** @return array<HasSolutionsForThrowable> */
protected function getProviderClassesForType(string $type): array
{
$relativePath = $this->config[$type] ?? null;
Expand All @@ -56,7 +62,7 @@ protected function getProviderClassesForType(string $type): array

$files = glob($globPattern);

if (!$files) {
if (! $files) {
return [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
use Spatie\ErrorSolutions\Contracts\BaseSolution;
use Spatie\ErrorSolutions\Contracts\HasSolutionsForThrowable;
use Spatie\ErrorSolutions\Contracts\Solution;
use Spatie\LaravelIgnition\Exceptions\ViewException as IgnitionViewException;
use Spatie\LaravelFlare\Exceptions\ViewException as FlareViewException;
use Spatie\ErrorSolutions\Solutions\Laravel\MakeViewVariableOptionalSolution;
use Spatie\ErrorSolutions\Solutions\Laravel\SuggestCorrectVariableNameSolution;
use Spatie\LaravelFlare\Exceptions\ViewException as FlareViewException;
use Spatie\LaravelIgnition\Exceptions\ViewException as IgnitionViewException;
use Throwable;

class UndefinedViewVariableSolutionProvider implements HasSolutionsForThrowable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use InvalidArgumentException;
use Spatie\ErrorSolutions\Contracts\BaseSolution;
use Spatie\ErrorSolutions\Contracts\HasSolutionsForThrowable;
use Spatie\ErrorSolutions\Support\Laravel\StringComparator;
use Spatie\Ignition\Exceptions\ViewException as IgnitionViewException;
use Spatie\LaravelFlare\Exceptions\ViewException as FlareViewException;
use Spatie\ErrorSolutions\Support\Laravel\StringComparator;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use Throwable;
Expand Down
1 change: 0 additions & 1 deletion src/Support/AiPromptRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ public function renderAsString(array $data, string $viewPath): string
return ob_get_clean();
}
}

2 changes: 1 addition & 1 deletion src/Support/Laravel/LivewireComponentParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class LivewireComponentParser
/** @var class-string<Component> */
protected string $componentClass;

/** @var ReflectionClass<Component> */
/** @var ReflectionClass<Component> */
protected ReflectionClass $reflectionClass;

public static function create(string $componentAlias): self
Expand Down
4 changes: 2 additions & 2 deletions tests/DiscoverSolutionProvidersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
use Spatie\ErrorSolutions\Contracts\HasSolutionsForThrowable;
use Spatie\ErrorSolutions\DiscoverSolutionProviders;

it('can get all solution providers', function() {
it('can get all solution providers', function () {
$providers = DiscoverSolutionProviders::for(['php', 'laravel']);

expect($providers)
->not()->toBeEmpty()
->toImplement(HasSolutionsForThrowable::class);
});

it('will discover more solution providers for more types', function() {
it('will discover more solution providers for more types', function () {
$phpProviders = DiscoverSolutionProviders::for(['php']);

$laravelProviders = DiscoverSolutionProviders::for(['php', 'laravel']);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

use Illuminate\Support\Facades\View;
use Spatie\LaravelIgnition\Solutions\MakeViewVariableOptionalSolution;
use Spatie\ErrorSolutions\Support\Laravel\Composer\ComposerClassMap;
use Spatie\LaravelIgnition\Solutions\MakeViewVariableOptionalSolution;

beforeEach(function () {
View::addLocation(__DIR__.'/../stubs/views');
Expand Down
8 changes: 0 additions & 8 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
namespace Spatie\ErrorSolutions\Tests;

use Illuminate\Foundation\Testing\Concerns\MakesHttpRequests;
use Illuminate\Http\Request;
use Spatie\FlareClient\Glows\Glow;
use Spatie\FlareClient\Report;
use Spatie\LaravelIgnition\Facades\Flare;
use Spatie\LaravelIgnition\IgnitionServiceProvider;
use Spatie\LaravelIgnition\Tests\TestClasses\FakeTime;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
use function Spatie\LaravelIgnition\Tests\config;

class TestCase extends \Orchestra\Testbench\TestCase
{
Expand Down

0 comments on commit 9782ba6

Please sign in to comment.