Completed
Pull Request — develop (#161)
by Wachter
22:54 queued 09:56
created

ArticleInitializer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 46
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A initialize() 0 15 2
1
<?php
2
3
/*
4
 * This file is part of Sulu.
5
 *
6
 * (c) MASSIVE ART WebServices GmbH
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Sulu\Bundle\ArticleBundle\Document\Initializer;
13
14
use Sulu\Bundle\DocumentManagerBundle\Initializer\InitializerInterface;
15
use Sulu\Component\DocumentManager\NodeManager;
16
use Sulu\Component\DocumentManager\PathBuilder;
17
use Sulu\Component\PHPCR\SessionManager\SessionManagerInterface;
18
use Symfony\Component\Console\Output\OutputInterface;
19
20
/**
21
 * Initializes custom-url nodes.
22
 */
23
class ArticleInitializer implements InitializerInterface
24
{
25
    /**
26
     * @var NodeManager
27
     */
28
    private $nodeManager;
29
30
    /**
31
     * @var PathBuilder
32
     */
33
    private $pathBuilder;
34
35
    /**
36
     * @var SessionManagerInterface
37
     */
38
    private $sessionManager;
39
40 1
    public function __construct(
41
        NodeManager $nodeManager,
42
        PathBuilder $pathBuilder,
43
        SessionManagerInterface $sessionManager
44
    ) {
45 1
        $this->nodeManager = $nodeManager;
46 1
        $this->pathBuilder = $pathBuilder;
47 1
        $this->sessionManager = $sessionManager;
48 1
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 1
    public function initialize(OutputInterface $output, $purge = false)
54
    {
55 1
        $nodeTypeManager = $this->sessionManager->getSession()->getWorkspace()->getNodeTypeManager();
0 ignored issues
show
Deprecated Code introduced by
The method Sulu\Component\PHPCR\Ses...Interface::getSession() has been deprecated with message: Use the doctrine_phpcr service to retrieve the session

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
56 1
        $nodeTypeManager->registerNodeType(new ArticleNodeType(), true);
57 1
        $nodeTypeManager->registerNodeType(new ArticlePageNodeType(), true);
58
59 1
        $articlesPath = $this->pathBuilder->build(['%base%', '%articles%']);
60 1
        if (true === $this->nodeManager->has($articlesPath)) {
61
            $output->writeln(sprintf('  [ ] <info>Articles path:</info>: %s ', $articlesPath));
62
        } else {
63 1
            $output->writeln(sprintf('  [+] <info>Articles path:</info>: %s ', $articlesPath));
64 1
            $this->nodeManager->createPath($articlesPath);
65 1
            $this->nodeManager->save();
66
        }
67 1
    }
68
}
69