• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Dropelikeit / laravel-jms-serializer / 9061496370

13 May 2024 10:39AM UTC coverage: 97.714% (-1.1%) from 98.857%
9061496370

Pull #35

github

Dropelikeit
Remove unused code and update tests

The commit involves the removal of several unused lines of constants and code from ResponseFactory and composer.json. In addition, tests have also been updated to assert the instance type of ResponseFactory whenever it's gotten from the application container. Improvements were made to the type annotations in the ResponseFactory tests for clarity.
Pull Request #35: Feature/add laravel 11 support and improve test quality

1 of 4 new or added lines in 1 file covered. (25.0%)

171 of 175 relevant lines covered (97.71%)

6.47 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.47
/src/ServiceProvider.php
1
<?php
2
declare(strict_types=1);
3

4
namespace Dropelikeit\LaravelJmsSerializer;
5

6
use Dropelikeit\LaravelJmsSerializer\Config\Config;
7
use Dropelikeit\LaravelJmsSerializer\Contracts\CustomHandlerConfiguration;
8
use Dropelikeit\LaravelJmsSerializer\Contracts\ResponseBuilder;
9
use Dropelikeit\LaravelJmsSerializer\Http\Responses\ResponseFactory;
10
use Dropelikeit\LaravelJmsSerializer\Serializer\Factory;
11
use Illuminate\Config\Repository;
12
use Illuminate\Foundation\Application;
13
use Illuminate\Support\Facades\Storage;
14
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
15
use function sprintf;
16

17
use Webmozart\Assert\Assert;
18

19
/**
20
 * @author Marcel Strahl <info@marcel-strahl.de>
21
 */
22
final class ServiceProvider extends BaseServiceProvider
23
{
24
    /**
25
     * @description Register any application services.
26
     */
27
    public function register(): void
28
    {
29
        $configPath = __DIR__ . '/../config/laravel-jms-serializer.php';
1✔
30
        $this->mergeConfigFrom($configPath, 'laravel-jms-serializer');
1✔
31

32
        /** @var Repository $configRepository */
33
        $configRepository = $this->app->get('config');
1✔
34

35
        $cacheDir = $this->app->storagePath('framework/cache/data');
1✔
36
        if (!Storage::exists($cacheDir)) {
1✔
37
            Storage::makeDirectory($cacheDir);
1✔
38
        }
39

40
        $shouldSerializeNull = (bool) $configRepository
1✔
41
            ->get('laravel-jms-serializer.serialize_null', true);
1✔
42
        $serializeType = $configRepository
1✔
43
            ->get('laravel-jms-serializer.serialize_type', Contracts\Config::SERIALIZE_TYPE_JSON);
1✔
44
        Assert::stringNotEmpty($serializeType);
1✔
45
        $debug = (bool) $configRepository->get('laravel-jms-serializer.debug', false);
1✔
46
        $addDefaultHandlers = (bool) $configRepository->get(
1✔
47
            'laravel-jms-serializer.add_default_handlers',
1✔
48
            true
1✔
49
        );
1✔
50
        /** @var array<int, CustomHandlerConfiguration> $customHandlers */
51
        $customHandlers = (array) $configRepository->get('laravel-jms-serializer.custom_handlers', []);
1✔
52

53
        $config = Config::fromConfig([
1✔
54
            'serialize_null' => $shouldSerializeNull,
1✔
55
            'cache_dir' => $cacheDir,
1✔
56
            'serialize_type' => $serializeType,
1✔
57
            'debug' => $debug,
1✔
58
            'add_default_handlers' => $addDefaultHandlers,
1✔
59
            'custom_handlers' => $customHandlers,
1✔
60
        ]);
1✔
61

62
        $this->app->singleton(ResponseFactory::class, static function () use ($config): ResponseFactory {
1✔
63
            return new ResponseFactory((new Factory())->getSerializer($config), $config);
×
64
        });
1✔
65

66
        $this->app->bind(ResponseBuilder::class, ResponseFactory::class);
1✔
67

68
        $this->app->bind('ResponseFactory', static function (Application $app): ResponseFactory {
1✔
NEW
69
            $responseFactory = $app->get(ResponseFactory::class);
×
NEW
70
            Assert::isInstanceOf($responseFactory, ResponseFactory::class);
×
71

NEW
72
            return $responseFactory;
×
73
        });
1✔
74
    }
75

76
    /**
77
     * @description Bootstrap the application events.
78
     */
79
    public function boot(): void
80
    {
81
        $configPath = sprintf('%s/../config/laravel-jms-serializer.php', __DIR__);
1✔
82
        Assert::stringNotEmpty($configPath);
1✔
83

84
        $this->publishes([$configPath => $this->getConfigPath()], 'laravel-jms');
1✔
85
    }
86

87
    /**
88
     * @description Get the config path
89
     *
90
     * @return string
91
     */
92
    private function getConfigPath(): string
93
    {
94
        return config_path('laravel-jms-serializer.php');
1✔
95
    }
96
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc