Completed
Push — ezp-30616-follow-up ( de1597...f1c1e1 )
by
unknown
14:34
created

URLService::updateUrl()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 2
dl 0
loc 27
rs 9.488
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Publish\API\Repository\Events;
10
11
use eZ\Publish\API\Repository\Events\URL\BeforeUpdateUrlEvent as BeforeUpdateUrlEventInterface;
12
use eZ\Publish\API\Repository\Events\URL\UpdateUrlEvent as UpdateUrlEventInterface;
13
use eZ\Publish\API\Repository\URLService as URLServiceInterface;
14
use eZ\Publish\API\Repository\Values\URL\URL;
15
use eZ\Publish\API\Repository\Values\URL\URLUpdateStruct;
16
use eZ\Publish\API\Repository\Events\URL\BeforeUpdateUrlEvent;
17
use eZ\Publish\API\Repository\Events\URL\UpdateUrlEvent;
18
use eZ\Publish\SPI\Repository\Decorator\URLServiceDecorator;
19
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
20
21
class URLService extends URLServiceDecorator
22
{
23
    /** @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface */
24
    protected $eventDispatcher;
25
26
    public function __construct(
27
        URLServiceInterface $innerService,
28
        EventDispatcherInterface $eventDispatcher
29
    ) {
30
        parent::__construct($innerService);
31
32
        $this->eventDispatcher = $eventDispatcher;
33
    }
34
35
    public function updateUrl(
36
        URL $url,
37
        URLUpdateStruct $struct
38
    ) {
39
        $eventData = [
40
            $url,
41
            $struct,
42
        ];
43
44
        $beforeEvent = new BeforeUpdateUrlEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeUpdateUrlEvent::__construct() misses a required argument $struct.

This check looks for function calls that miss required arguments.

Loading history...
45
46
        $this->eventDispatcher->dispatch($beforeEvent, BeforeUpdateUrlEventInterface::class);
47
        if ($beforeEvent->isPropagationStopped()) {
48
            return $beforeEvent->getUpdatedUrl();
49
        }
50
51
        $updatedUrl = $beforeEvent->hasUpdatedUrl()
52
            ? $beforeEvent->getUpdatedUrl()
53
            : $this->innerService->updateUrl($url, $struct);
54
55
        $this->eventDispatcher->dispatch(
56
            new UpdateUrlEvent($updatedUrl, ...$eventData),
0 ignored issues
show
Bug introduced by
The call to UpdateUrlEvent::__construct() misses a required argument $struct.

This check looks for function calls that miss required arguments.

Loading history...
57
            UpdateUrlEventInterface::class
58
        );
59
60
        return $updatedUrl;
61
    }
62
}
63