Completed
Push — master ( b7d603...d97993 )
by Paweł
07:44
created

PackagePreviewTokenFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 45
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 4 1
A createTokenizedWith() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Core Bundle.
7
 *
8
 * Copyright 2018 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2018 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\CoreBundle\Factory;
18
19
use SWP\Bundle\ContentBundle\Model\RouteInterface;
20
use SWP\Bundle\CoreBundle\Model\PackagePreviewTokenInterface;
21
use SWP\Component\Common\Generator\GeneratorInterface;
22
use SWP\Component\Storage\Factory\FactoryInterface;
23
24
final class PackagePreviewTokenFactory implements PackagePreviewTokenFactoryInterface
25
{
26
    /**
27
     * @var FactoryInterface
28
     */
29
    private $baseFactory;
30
31
    /**
32
     * @var GeneratorInterface
33
     */
34
    private $randomnessGenerator;
35
36
    /**
37
     * PackagePreviewTokenFactory constructor.
38
     *
39
     * @param FactoryInterface   $baseFactory
40
     * @param GeneratorInterface $randomnessGenerator
41
     */
42
    public function __construct(FactoryInterface $baseFactory, GeneratorInterface $randomnessGenerator)
43
    {
44
        $this->baseFactory = $baseFactory;
45
        $this->randomnessGenerator = $randomnessGenerator;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function create()
52
    {
53
        return $this->baseFactory->create();
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function createTokenizedWith(RouteInterface $route, string $body): PackagePreviewTokenInterface
60
    {
61
        $packagePreviewToken = $this->create();
62
        $packagePreviewToken->setRoute($route);
63
        $packagePreviewToken->setBody($body);
64
        $packagePreviewToken->setToken($this->randomnessGenerator->generate(36));
65
66
        return $packagePreviewToken;
67
    }
68
}
69