Passed
Push — feature/more-tests ( 43cd4c )
by Tomáš
04:29
created
src/ProtectedReferencesChecker.php 1 patch
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -7,90 +7,90 @@
 block discarded – undo
7 7
 use Symfony\Bridge\Doctrine\RegistryInterface;
8 8
 
9 9
 class ProtectedReferencesChecker {
10
-	/**
11
-	 * @var RegistryInterface
12
-	 */
13
-	private $doctrine;
14
-	/**
15
-	 * @var DefinitionRegistry
16
-	 */
17
-	private $registry;
10
+    /**
11
+     * @var RegistryInterface
12
+     */
13
+    private $doctrine;
14
+    /**
15
+     * @var DefinitionRegistry
16
+     */
17
+    private $registry;
18 18
 
19
-	public function __construct(RegistryInterface $doctrine, DefinitionRegistry $registry) {
20
-		$this->doctrine = $doctrine;
21
-		$this->registry = $registry;
22
-	}
19
+    public function __construct(RegistryInterface $doctrine, DefinitionRegistry $registry) {
20
+        $this->doctrine = $doctrine;
21
+        $this->registry = $registry;
22
+    }
23 23
 
24
-	/**
25
-	 * @param string $class
26
-	 * @param array|null $ids
27
-	 * @return array
28
-	 */
29
-	public function findProtectedIdsByClass(string $class, array $ids = null) : array {
30
-		$keys = [];
31
-		foreach ($this->registry->keys() as $key) {
32
-			$definition = $this->registry->get($key);
33
-			if ($definition instanceof EntityDefinition and is_a($class, $definition->getClass(), true)) {
34
-				$keys[] = $definition->getKey();
35
-			}
36
-		}
24
+    /**
25
+     * @param string $class
26
+     * @param array|null $ids
27
+     * @return array
28
+     */
29
+    public function findProtectedIdsByClass(string $class, array $ids = null) : array {
30
+        $keys = [];
31
+        foreach ($this->registry->keys() as $key) {
32
+            $definition = $this->registry->get($key);
33
+            if ($definition instanceof EntityDefinition and is_a($class, $definition->getClass(), true)) {
34
+                $keys[] = $definition->getKey();
35
+            }
36
+        }
37 37
 
38
-		if (empty($keys)) {
39
-			return [];
40
-		}
38
+        if (empty($keys)) {
39
+            return [];
40
+        }
41 41
 
42
-		$qb = $this->doctrine->getEntityManagerForClass(ConfigurationValue::class)->createQueryBuilder();
43
-		$qb
44
-			->select('DISTINCT (v.value)')
45
-			->from(ConfigurationValue::class, 'v')
46
-			->where($qb->expr()->in('v.key', ':keys'))
47
-			->setParameter('keys', $keys);
42
+        $qb = $this->doctrine->getEntityManagerForClass(ConfigurationValue::class)->createQueryBuilder();
43
+        $qb
44
+            ->select('DISTINCT (v.value)')
45
+            ->from(ConfigurationValue::class, 'v')
46
+            ->where($qb->expr()->in('v.key', ':keys'))
47
+            ->setParameter('keys', $keys);
48 48
 
49
-		if ($ids !== null) {
50
-			$qb
51
-				->andWhere($qb->expr()->in('v.value', ':ids'))
52
-				->setParameter('ids', $ids);
53
-		}
49
+        if ($ids !== null) {
50
+            $qb
51
+                ->andWhere($qb->expr()->in('v.value', ':ids'))
52
+                ->setParameter('ids', $ids);
53
+        }
54 54
 
55
-		$protectedIds = $qb->getQuery()->getScalarResult();
56
-		return empty($protectedIds) ? [] : array_merge(...$protectedIds);
57
-	}
55
+        $protectedIds = $qb->getQuery()->getScalarResult();
56
+        return empty($protectedIds) ? [] : array_merge(...$protectedIds);
57
+    }
58 58
 
59
-	/**
60
-	 * @param $object
61
-	 * @throws ProtectedReferenceException
62
-	 * @throws \Doctrine\ORM\NoResultException
63
-	 * @throws \Doctrine\ORM\NonUniqueResultException
64
-	 */
65
-	public function checkReferenceForProtection($object) {
66
-		$id = $this->doctrine->getEntityManagerForClass(get_class($object))->getUnitOfWork()->getSingleIdentifierValue($object);
59
+    /**
60
+     * @param $object
61
+     * @throws ProtectedReferenceException
62
+     * @throws \Doctrine\ORM\NoResultException
63
+     * @throws \Doctrine\ORM\NonUniqueResultException
64
+     */
65
+    public function checkReferenceForProtection($object) {
66
+        $id = $this->doctrine->getEntityManagerForClass(get_class($object))->getUnitOfWork()->getSingleIdentifierValue($object);
67 67
 
68
-		$keys = [];
69
-		foreach ($this->registry->keys() as $key) {
70
-			$definition = $this->registry->get($key);
71
-			if ($definition instanceof EntityDefinition and is_a($object, $definition->getClass())) {
72
-				$keys[] = $definition->getKey();
73
-			}
74
-		}
68
+        $keys = [];
69
+        foreach ($this->registry->keys() as $key) {
70
+            $definition = $this->registry->get($key);
71
+            if ($definition instanceof EntityDefinition and is_a($object, $definition->getClass())) {
72
+                $keys[] = $definition->getKey();
73
+            }
74
+        }
75 75
 
76
-		if (empty($keys)) {
77
-			return;
78
-		}
76
+        if (empty($keys)) {
77
+            return;
78
+        }
79 79
 
80
-		$repo = $this->doctrine->getEntityManagerForClass(ConfigurationValue::class);
81
-		$qb = $repo->createQueryBuilder();
82
-		$countProtected = $qb
83
-			->select('count(v)')
84
-			->from(ConfigurationValue::class, 'v')
85
-			->where($qb->expr()->in('v.key', ':keys'))
86
-			->andWhere($qb->expr()->eq('v.value', ':id'))
87
-			->getQuery()
88
-			->setParameter('keys', $keys)
89
-			->setParameter('id', $id)
90
-			->getSingleScalarResult();
80
+        $repo = $this->doctrine->getEntityManagerForClass(ConfigurationValue::class);
81
+        $qb = $repo->createQueryBuilder();
82
+        $countProtected = $qb
83
+            ->select('count(v)')
84
+            ->from(ConfigurationValue::class, 'v')
85
+            ->where($qb->expr()->in('v.key', ':keys'))
86
+            ->andWhere($qb->expr()->eq('v.value', ':id'))
87
+            ->getQuery()
88
+            ->setParameter('keys', $keys)
89
+            ->setParameter('id', $id)
90
+            ->getSingleScalarResult();
91 91
 
92
-		if ($countProtected > 0) {
93
-			throw new ProtectedReferenceException("Can't delete protected reference.");
94
-		}
95
-	}
92
+        if ($countProtected > 0) {
93
+            throw new ProtectedReferenceException("Can't delete protected reference.");
94
+        }
95
+    }
96 96
 }
Please login to merge, or discard this patch.
src/Definition.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -3,20 +3,20 @@
 block discarded – undo
3 3
 namespace OneGuard\Bundle\DynamicConfigurationBundle;
4 4
 
5 5
 abstract class Definition {
6
-	private $key;
6
+    private $key;
7 7
 
8
-	/**
9
-	 * Definition constructor.
10
-	 * @param $key
11
-	 */
12
-	public function __construct($key) {
13
-		$this->key = $key;
14
-	}
8
+    /**
9
+     * Definition constructor.
10
+     * @param $key
11
+     */
12
+    public function __construct($key) {
13
+        $this->key = $key;
14
+    }
15 15
 
16
-	/**
17
-	 * @return mixed
18
-	 */
19
-	public function getKey() {
20
-		return $this->key;
21
-	}
16
+    /**
17
+     * @return mixed
18
+     */
19
+    public function getKey() {
20
+        return $this->key;
21
+    }
22 22
 }
Please login to merge, or discard this patch.
src/DependencyInjection/OneGuardDynamicConfigurationExtension.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -9,39 +9,39 @@
 block discarded – undo
9 9
 use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
10 10
 
11 11
 class OneGuardDynamicConfigurationExtension extends Extension {
12
-	/**
13
-	 * @param array $configs
14
-	 * @param ContainerBuilder $container
15
-	 * @throws \Exception
16
-	 */
17
-	public function load(array $configs, ContainerBuilder $container) {
18
-		$loader = new YamlFileLoader(
19
-			$container,
20
-			new FileLocator(__DIR__.'/../Resources/config')
21
-		);
22
-		$loader->load('services.yml');
12
+    /**
13
+     * @param array $configs
14
+     * @param ContainerBuilder $container
15
+     * @throws \Exception
16
+     */
17
+    public function load(array $configs, ContainerBuilder $container) {
18
+        $loader = new YamlFileLoader(
19
+            $container,
20
+            new FileLocator(__DIR__.'/../Resources/config')
21
+        );
22
+        $loader->load('services.yml');
23 23
 
24
-		$configuration = new Configuration();
25
-		$config = $this->processConfiguration($configuration, $configs);
24
+        $configuration = new Configuration();
25
+        $config = $this->processConfiguration($configuration, $configs);
26 26
 
27
-		$container->setParameter('one_guard.dynamic_configuration.translation_domain', $config['translation_domain']);
28
-		$container->setParameter('one_guard.dynamic_configuration.translation_prefix', $config['translation_prefix']);
27
+        $container->setParameter('one_guard.dynamic_configuration.translation_domain', $config['translation_domain']);
28
+        $container->setParameter('one_guard.dynamic_configuration.translation_prefix', $config['translation_prefix']);
29 29
 
30
-		$register = $container->getDefinition(DefinitionRegistry::class);
30
+        $register = $container->getDefinition(DefinitionRegistry::class);
31 31
 
32
-		foreach ($config['definitions'] as $key => $definitionConfig) {
33
-			switch ($definitionConfig['type']) {
34
-				case 'entity':
35
-					$register->addMethodCall('registerEntity', [
36
-						$key,
37
-						$definitionConfig['options']['class'],
38
-						$definitionConfig['options']['choice_label']
39
-					]);
40
-					break;
41
-				case 'string':
42
-					$register->addMethodCall('registerString', [$key]);
43
-					break;
44
-			}
45
-		}
46
-	}
32
+        foreach ($config['definitions'] as $key => $definitionConfig) {
33
+            switch ($definitionConfig['type']) {
34
+                case 'entity':
35
+                    $register->addMethodCall('registerEntity', [
36
+                        $key,
37
+                        $definitionConfig['options']['class'],
38
+                        $definitionConfig['options']['choice_label']
39
+                    ]);
40
+                    break;
41
+                case 'string':
42
+                    $register->addMethodCall('registerString', [$key]);
43
+                    break;
44
+            }
45
+        }
46
+    }
47 47
 }
Please login to merge, or discard this patch.
src/DependencyInjection/Configuration.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -6,32 +6,32 @@  discard block
 block discarded – undo
6 6
 use Symfony\Component\Config\Definition\ConfigurationInterface;
7 7
 
8 8
 class Configuration implements ConfigurationInterface {
9
-	public function getConfigTreeBuilder() {
10
-		$treeBuilder = new TreeBuilder();
11
-		$rootNode = $treeBuilder->root('one_guard_dynamic_configuration');
9
+    public function getConfigTreeBuilder() {
10
+        $treeBuilder = new TreeBuilder();
11
+        $rootNode = $treeBuilder->root('one_guard_dynamic_configuration');
12 12
 
13
-		$rootNode
14
-			->addDefaultsIfNotSet()
15
-			->children()
16
-				->arrayNode('definitions')
17
-					->prototype('array')
18
-						->children()
19
-							->enumNode('type')
20
-								->values(['entity', 'string'])
21
-								->isRequired()
22
-							->end()
23
-							->arrayNode('options')
24
-								->children()
25
-									->scalarNode('class')
26
-										->validate()
27
-											->ifTrue(function ($class) {
28
-												return !class_exists($class);
29
-											})
30
-											->thenInvalid("Class doesn't exist.")
31
-										->end()
32
-									->end()
33
-									->scalarNode('choice_label')->end()
34
-								->end()
13
+        $rootNode
14
+            ->addDefaultsIfNotSet()
15
+            ->children()
16
+                ->arrayNode('definitions')
17
+                    ->prototype('array')
18
+                        ->children()
19
+                            ->enumNode('type')
20
+                                ->values(['entity', 'string'])
21
+                                ->isRequired()
22
+                            ->end()
23
+                            ->arrayNode('options')
24
+                                ->children()
25
+                                    ->scalarNode('class')
26
+                                        ->validate()
27
+                                            ->ifTrue(function ($class) {
28
+                                                return !class_exists($class);
29
+                                            })
30
+                                            ->thenInvalid("Class doesn't exist.")
31
+                                        ->end()
32
+                                    ->end()
33
+                                    ->scalarNode('choice_label')->end()
34
+                                ->end()
35 35
 //								->validate()
36 36
 //									->ifTrue(function ($options) {
37 37
 //										if (!empty($options['class'])) {
@@ -42,19 +42,19 @@  discard block
 block discarded – undo
42 42
 //									})
43 43
 //									->thenInvalid("Property not accessible.")
44 44
 //								->end()
45
-							->end()
46
-						->end()
47
-					->end()
48
-				->end()
49
-				->scalarNode('translation_domain')
50
-					->defaultValue('messages')
51
-					->cannotBeEmpty()
52
-				->end()
53
-				->scalarNode('translation_prefix')
54
-					->defaultValue('')
55
-				->end()
56
-			->end();
45
+                            ->end()
46
+                        ->end()
47
+                    ->end()
48
+                ->end()
49
+                ->scalarNode('translation_domain')
50
+                    ->defaultValue('messages')
51
+                    ->cannotBeEmpty()
52
+                ->end()
53
+                ->scalarNode('translation_prefix')
54
+                    ->defaultValue('')
55
+                ->end()
56
+            ->end();
57 57
 
58
-		return $treeBuilder;
59
-	}
58
+        return $treeBuilder;
59
+    }
60 60
 }
Please login to merge, or discard this patch.
src/Controller/ConfigurationValueController.php 1 patch
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -17,93 +17,93 @@
 block discarded – undo
17 17
  * @Route(path="/configuration-value")
18 18
  */
19 19
 class ConfigurationValueController extends Controller {
20
-	/**
21
-	 * @var \Doctrine\ORM\EntityManagerInterface
22
-	 */
23
-	private $entityManager;
20
+    /**
21
+     * @var \Doctrine\ORM\EntityManagerInterface
22
+     */
23
+    private $entityManager;
24 24
 
25
-	/**
26
-	 * @var DefinitionRegistry
27
-	 */
28
-	private $registry;
25
+    /**
26
+     * @var DefinitionRegistry
27
+     */
28
+    private $registry;
29 29
 
30
-	/**
31
-	 * @var ConfigurationResolverFactory
32
-	 */
33
-	private $factory;
30
+    /**
31
+     * @var ConfigurationResolverFactory
32
+     */
33
+    private $factory;
34 34
 
35
-	public function __construct(
36
-		RegistryInterface $doctrine,
37
-		DefinitionRegistry $registry,
38
-		ConfigurationResolverFactory $factory
39
-	) {
40
-		$this->entityManager = $doctrine->getEntityManagerForClass(ConfigurationValue::class);
41
-		$this->registry = $registry;
42
-		$this->factory = $factory;
43
-	}
35
+    public function __construct(
36
+        RegistryInterface $doctrine,
37
+        DefinitionRegistry $registry,
38
+        ConfigurationResolverFactory $factory
39
+    ) {
40
+        $this->entityManager = $doctrine->getEntityManagerForClass(ConfigurationValue::class);
41
+        $this->registry = $registry;
42
+        $this->factory = $factory;
43
+    }
44 44
 
45
-	/**
46
-	 * @Route(path="/assign", name="configurationValue.assign")
47
-	 * @throws \Doctrine\ORM\OptimisticLockException
48
-	 */
49
-	public function assignAction(Request $request) {
50
-		$configurationValues = $this->entityManager->getRepository(ConfigurationValue::class)->findAll();
51
-		$existingValueKeys = array_map(function (ConfigurationValue $value) {
52
-			return $value->getKey();
53
-		}, $configurationValues);
54
-		$missingValueKeys = array_diff($this->registry->keys(), $existingValueKeys);
55
-		$configurationValues = array_merge(
56
-			$configurationValues,
57
-			array_map(function (string $key) {
58
-				$value = new ConfigurationValue();
59
-				$value->setKey($key);
60
-				return $value;
61
-			}, $missingValueKeys)
62
-		);
45
+    /**
46
+     * @Route(path="/assign", name="configurationValue.assign")
47
+     * @throws \Doctrine\ORM\OptimisticLockException
48
+     */
49
+    public function assignAction(Request $request) {
50
+        $configurationValues = $this->entityManager->getRepository(ConfigurationValue::class)->findAll();
51
+        $existingValueKeys = array_map(function (ConfigurationValue $value) {
52
+            return $value->getKey();
53
+        }, $configurationValues);
54
+        $missingValueKeys = array_diff($this->registry->keys(), $existingValueKeys);
55
+        $configurationValues = array_merge(
56
+            $configurationValues,
57
+            array_map(function (string $key) {
58
+                $value = new ConfigurationValue();
59
+                $value->setKey($key);
60
+                return $value;
61
+            }, $missingValueKeys)
62
+        );
63 63
 
64
-		$form = $this->createForm(ConfigurationValuesType::class, ['configurationValues' => $configurationValues]);
65
-		$form->handleRequest($request);
66
-		if ($form->isSubmitted() and $form->isValid()) {
67
-			/* @var $configurationValue ConfigurationValue */
68
-			foreach ($form->get('configurationValues')->getData() as $configurationValue) {
69
-				$isPersisted = \Doctrine\ORM\UnitOfWork::STATE_MANAGED ===
70
-					$this->entityManager->getUnitOfWork()->getEntityState($configurationValue);
64
+        $form = $this->createForm(ConfigurationValuesType::class, ['configurationValues' => $configurationValues]);
65
+        $form->handleRequest($request);
66
+        if ($form->isSubmitted() and $form->isValid()) {
67
+            /* @var $configurationValue ConfigurationValue */
68
+            foreach ($form->get('configurationValues')->getData() as $configurationValue) {
69
+                $isPersisted = \Doctrine\ORM\UnitOfWork::STATE_MANAGED ===
70
+                    $this->entityManager->getUnitOfWork()->getEntityState($configurationValue);
71 71
 
72
-				if ($configurationValue->getValue() === null and $isPersisted) {
73
-					$this->entityManager->remove($configurationValue);
74
-				} else if ($configurationValue->getValue() !== null and !$isPersisted) {
75
-					$this->entityManager->persist($configurationValue);
76
-				}
77
-			}
78
-			$this->entityManager->flush();
72
+                if ($configurationValue->getValue() === null and $isPersisted) {
73
+                    $this->entityManager->remove($configurationValue);
74
+                } else if ($configurationValue->getValue() !== null and !$isPersisted) {
75
+                    $this->entityManager->persist($configurationValue);
76
+                }
77
+            }
78
+            $this->entityManager->flush();
79 79
 
80
-			return $this->redirectToRoute('configurationValue.view');
81
-		}
80
+            return $this->redirectToRoute('configurationValue.view');
81
+        }
82 82
 
83
-		return $this->render('OneGuardDynamicConfigurationBundle:ConfigurationValue:assign.html.twig', ['form' => $form->createView()]);
84
-	}
83
+        return $this->render('OneGuardDynamicConfigurationBundle:ConfigurationValue:assign.html.twig', ['form' => $form->createView()]);
84
+    }
85 85
 
86
-	/**
87
-	 * @Route(path="/view", name="configurationValue.view")
88
-	 */
89
-	public function viewAction() {
90
-		/* @var $configurationValues ConfigurationValue[] */
91
-		$configurationValues = $this->entityManager->getRepository(ConfigurationValue::class)->findAll();
92
-		$labels = [];
93
-		$propertyAccessor = new PropertyAccessor();
94
-		foreach ($configurationValues as $configurationValue) {
95
-			$definition = $this->registry->get($configurationValue->getKey());
96
-			if ($definition instanceof EntityDefinition) {
97
-				$object = $this->factory->create($definition->getKey())->resolve();
98
-				$labels[$definition->getKey()] = $propertyAccessor->getValue($object, $definition->getChoiceLabel());
99
-			}
100
-		}
86
+    /**
87
+     * @Route(path="/view", name="configurationValue.view")
88
+     */
89
+    public function viewAction() {
90
+        /* @var $configurationValues ConfigurationValue[] */
91
+        $configurationValues = $this->entityManager->getRepository(ConfigurationValue::class)->findAll();
92
+        $labels = [];
93
+        $propertyAccessor = new PropertyAccessor();
94
+        foreach ($configurationValues as $configurationValue) {
95
+            $definition = $this->registry->get($configurationValue->getKey());
96
+            if ($definition instanceof EntityDefinition) {
97
+                $object = $this->factory->create($definition->getKey())->resolve();
98
+                $labels[$definition->getKey()] = $propertyAccessor->getValue($object, $definition->getChoiceLabel());
99
+            }
100
+        }
101 101
 
102
-		return $this->render('OneGuardDynamicConfigurationBundle:ConfigurationValue:view.html.twig', [
103
-			'configurationValues' => $configurationValues,
104
-			'translationDomain' => $this->getParameter('one_guard.dynamic_configuration.translation_domain'),
105
-			'translationPrefix' => $this->getParameter('one_guard.dynamic_configuration.translation_prefix'),
106
-			'labels' => $labels
107
-		]);
108
-	}
102
+        return $this->render('OneGuardDynamicConfigurationBundle:ConfigurationValue:view.html.twig', [
103
+            'configurationValues' => $configurationValues,
104
+            'translationDomain' => $this->getParameter('one_guard.dynamic_configuration.translation_domain'),
105
+            'translationPrefix' => $this->getParameter('one_guard.dynamic_configuration.translation_prefix'),
106
+            'labels' => $labels
107
+        ]);
108
+    }
109 109
 }
Please login to merge, or discard this patch.