Skip to content

Commit 58f0dbc

Browse files
committed
fix
1 parent 2f8f6d2 commit 58f0dbc

File tree

10 files changed

+74
-13
lines changed

10 files changed

+74
-13
lines changed

Diff for: phpstan.neon

-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
includes:
22
- phpstan-baseline.neon
3-
43
- vendor/phpstan/phpstan-webmozart-assert/extension.neon
54
- vendor/phpstan/phpstan-phpunit/extension.neon
6-
75
- vendor/phpstan/phpstan-phpunit/rules.neon
86

97
parameters:

Diff for: src/Bundle/Parser/OptionsParser.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace Sylius\Bundle\GridBundle\Parser;
1515

16+
use Sylius\Component\Grid\Exception\InvalidArgumentException;
17+
1618
final class OptionsParser implements OptionsParserInterface
1719
{
1820
public function parseOptions(array $parameters): array
@@ -45,7 +47,7 @@ private function parseOption(mixed $parameter): mixed
4547
private function parseOptionCallable(string $callable): \Closure
4648
{
4749
if (!is_callable($callable)) {
48-
throw new \RuntimeException(\sprintf('%s is not a callable.', $callable));
50+
throw new InvalidArgumentException(\sprintf('%s is not a callable.', $callable));
4951
}
5052

5153
return $callable(...);

Diff for: src/Bundle/Resources/config/services.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
</service>
130130
<service id="Sylius\Bundle\GridBundle\Maker\MakeGrid" alias="sylius.grid.maker" />
131131

132-
<service id="sylius_grid.options_parser" class="Sylius\Bundle\GridBundle\Parser\OptionsParser" />
133-
<service id="Sylius\Bundle\GridBundle\Parser\OptionsParserInterface" alias="sylius_grid.options_parser" />
132+
<service id="sylius.grid.options_parser" class="Sylius\Bundle\GridBundle\Parser\OptionsParser" public="false" />
133+
<service id="Sylius\Bundle\GridBundle\Parser\OptionsParserInterface" alias="sylius.grid.options_parser" public="false" />
134134
</services>
135135
</container>

Diff for: src/Bundle/Resources/config/services/twig.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<argument>@SyliusGrid/_grid.html.twig</argument>
2424
<argument>%sylius.grid.templates.action%</argument>
2525
<argument>%sylius.grid.templates.filter%</argument>
26-
<argument type="service" id="sylius_grid.options_parser" />
26+
<argument type="service" id="sylius.grid.options_parser" />
2727
</service>
2828
<service id="Sylius\Bundle\GridBundle\Renderer\TwigGridRenderer" alias="sylius.grid.renderer.twig" />
2929

Diff for: src/Bundle/Tests/Unit/Parser/OptionsParserTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use PHPUnit\Framework\TestCase;
1717
use Sylius\Bundle\GridBundle\Parser\OptionsParser;
1818
use Sylius\Bundle\GridBundle\Parser\OptionsParserInterface;
19+
use Sylius\Component\Grid\Exception\InvalidArgumentException;
1920

2021
final class OptionsParserTest extends TestCase
2122
{
@@ -24,7 +25,7 @@ public function testItImplementsOptionsParserInterface(): void
2425
$this->assertInstanceOf(OptionsParserInterface::class, new OptionsParser());
2526
}
2627

27-
public function testItParserOptionsWithCallable(): void
28+
public function testItParsesOptionsWithCallable(): void
2829
{
2930
$options = (new OptionsParser())->parseOptions([
3031
'type' => 'callable',
@@ -43,7 +44,7 @@ public function testItParserOptionsWithCallable(): void
4344

4445
public function testItFailsWhileParsingOptionsWithInvalidCallable(): void
4546
{
46-
$this->expectException(\RuntimeException::class);
47+
$this->expectException(InvalidArgumentException::class);
4748

4849
$options = (new OptionsParser())->parseOptions([
4950
'type' => 'callable',

Diff for: src/Component/Exception/ExceptionInterface.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Sylius Sp. z o.o.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Sylius\Component\Grid\Exception;
15+
16+
interface ExceptionInterface extends \Throwable
17+
{
18+
}

Diff for: src/Component/Exception/InvalidArgumentException.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Sylius Sp. z o.o.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Sylius\Component\Grid\Exception;
15+
16+
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
17+
{
18+
}

Diff for: src/Component/Exception/UnexpectedValueException.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Sylius Sp. z o.o.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Sylius\Component\Grid\Exception;
15+
16+
class UnexpectedValueException extends \UnexpectedValueException implements ExceptionInterface
17+
{
18+
}

Diff for: src/Component/FieldTypes/CallableFieldType.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use Sylius\Component\Grid\DataExtractor\DataExtractorInterface;
1717
use Sylius\Component\Grid\Definition\Field;
18+
use Sylius\Component\Grid\Exception\UnexpectedValueException;
1819
use Symfony\Component\OptionsResolver\OptionsResolver;
1920

2021
final class CallableFieldType implements FieldTypeInterface
@@ -30,8 +31,12 @@ public function render(Field $field, $data, array $options): string
3031

3132
try {
3233
$value = (string) $value;
33-
} catch (\Throwable) {
34-
throw new \RuntimeException(\sprintf('The callback for field "%s" returned a value that could not be converted to string.', $field->getName()));
34+
} catch (\Throwable $e) {
35+
throw new UnexpectedValueException(\sprintf(
36+
'Callable field (name "%s") returned value could not be converted to string: "%s".',
37+
$field->getName(),
38+
$e->getMessage(),
39+
));
3540
}
3641

3742
if ($options['htmlspecialchars']) {

Diff for: src/Component/spec/FieldTypes/CallableFieldTypeSpec.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use PhpSpec\ObjectBehavior;
1717
use Sylius\Component\Grid\DataExtractor\DataExtractorInterface;
1818
use Sylius\Component\Grid\Definition\Field;
19+
use Sylius\Component\Grid\Exception\UnexpectedValueException;
1920
use Sylius\Component\Grid\FieldTypes\FieldTypeInterface;
2021

2122
final class CallableFieldTypeSpec extends ObjectBehavior
@@ -70,9 +71,9 @@ function it_uses_data_extractor_to_obtain_data_and_passes_it_to_a_static_callabl
7071
DataExtractorInterface $dataExtractor,
7172
Field $field,
7273
): void {
73-
$dataExtractor->get($field, ['foo' => 'bar'])->willReturn('BAR');
74+
$dataExtractor->get($field, ['foo' => 'BAR'])->willReturn('BAR');
7475

75-
$this->render($field, ['foo' => 'bar'], [
76+
$this->render($field, ['foo' => 'BAR'], [
7677
'callable' => [self::class, 'callable'],
7778
'htmlspecialchars' => true,
7879
])->shouldReturn('bar');
@@ -86,7 +87,7 @@ function it_throws_an_exception_when_a_callable_return_value_cannot_be_casted_to
8687
$dataExtractor->get($field, ['foo' => 'bar'])->willReturn('BAR');
8788

8889
$this
89-
->shouldThrow(\RuntimeException::class)
90+
->shouldThrow(UnexpectedValueException::class)
9091
->during('render', [
9192
$field,
9293
['foo' => 'bar'],

0 commit comments

Comments
 (0)