Completed
Pull Request — master (#168)
by
unknown
02:59
created

ProfileManager   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 4
c 2
b 0
f 2
lcom 1
cbo 4
dl 0
loc 53
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getAllProfiles() 0 7 1
A createProfile() 0 13 2
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\SettingsBundle\Service;
13
14
use ONGR\SettingsBundle\Document\Profile;
15
use ONGR\ElasticsearchBundle\Service\Manager;
16
use ONGR\ElasticsearchDSL\Query\MatchAllQuery;
17
18
class ProfileManager
19
{
20
    /**
21
     * Elasticsearch manager
22
     *
23
     * @var Manager
24
     */
25
    private $manager;
26
27
    /**
28
     * ProfileFinder constructor.
29
     *
30
     * @param Manager $manager
31
     */
32
    public function __construct(Manager $manager)
33
    {
34
        $this->manager = $manager;
35
    }
36
37
    /**
38
     * Finds all profiles
39
     *
40
     * @returns array
41
     */
42
    public function getAllProfiles()
43
    {
44
        $repo = $this->manager->getRepository('ONGRSettingsBundle:Profile');
45
        $search = $repo->createSearch();
46
        $search->addQuery(new MatchAllQuery());
47
        return $repo->execute($search, 'array');
48
    }
49
50
    /**
51
     * Creates a new profile
52
     *
53
     * @param string $name
54
     * @param string $description
55
     * @param string $id
56
     */
57
    public function createProfile($name, $description, $id = '')
58
    {
59
        $profile = new Profile();
60
        if ($id != '') {
61
            $profile->setId($id);
62
        }
63
        $profile->setName($name);
64
        $profile->setDescription($description);
65
66
        $this->manager->persist($profile);
67
        $this->manager->commit();
68
        $this->manager->flush();
69
    }
70
}
71