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

Dropelikeit / laravel-jms-serializer / 9061239740

13 May 2024 10:20AM UTC coverage: 98.844% (-0.01%) from 98.857%
9061239740

Pull #35

github

Dropelikeit
Update .gitignore file

The .gitignore file was modified to optimize it for the project's current needs. Unnecessary Laravel specific ignores were removed and PHPUnit, Composer, and Package specific ignores were added. This change will ensure that irrelevant files are not tracked by the version control system.
Pull Request #35: Feature/add laravel 11 support and improve test quality

2 of 3 new or added lines in 1 file covered. (66.67%)

1 existing line in 1 file now uncovered.

171 of 173 relevant lines covered (98.84%)

6.54 hits per line

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

94.44
/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
UNCOV
69
            return $app->get(ResponseFactory::class);
×
70
        });
1✔
71
    }
72

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

81
        $this->publishes([$configPath => $this->getConfigPath()], 'laravel-jms');
1✔
82
    }
83

84
    /**
85
     * @description Get the config path
86
     *
87
     * @return string
88
     */
89
    private function getConfigPath(): string
90
    {
91
        return config_path('laravel-jms-serializer.php');
1✔
92
    }
93
}
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