Completed
Push — master ( 5a5af9...2d6d18 )
by Adam
02:03
created

FormFactory::create()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.2098

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 5
cts 7
cp 0.7143
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 2
crap 3.2098
1
<?php
2
/**
3
 * FormFactory.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        http://www.ipublikuj.eu
7
 * @author         Adam Kadlec http://www.ipublikuj.eu
8
 * @package        iPublikuj:Forms!
9
 * @subpackage     common
10
 * @since          5.0
11
 *
12
 * @date           10.06.14
13
 */
14
15
declare(strict_types = 1);
16
17
namespace IPub\Forms;
18
19
use Nette\Application;
20
use Nette\DI;
21
use Nette\Localization;
22
23
/**
24
 * Form factory
25
 *
26
 * @package        iPublikuj:Forms!
27
 * @subpackage     common
28
 *
29
 * @author         Adam Kadlec <[email protected]>
30
 */
31 1
final class FormFactory implements IFormFactory
32
{
33
	/**
34
	 * @var Localization\ITranslator|NULL
35
	 */
36
	private $translator;
37
38
	/**
39
	 * @var DI\Container
40
	 */
41
	private $container;
42
43
	/**
44
	 * @param Localization\ITranslator|NULL $translator
45
	 * @param DI\Container $container
46
	 */
47
	public function __construct(
48
		Localization\ITranslator $translator = NULL,
49
		DI\Container $container
50
	) {
51 1
		$this->translator = $translator;
52 1
		$this->container = $container;
53 1
	}
54
55
	/**
56
	 * {@inheritdoc}
57
	 */
58
	public function create(string $formClassName, ...$args) : Application\UI\Form
59
	{
60 1
		if (!class_exists($formClassName)) {
61
			throw new Exceptions\InvalidArgumentException('Factory form class isn\'t defined.');
62
		}
63
64
		/** @var Application\UI\Form $form */
65 1
		$form = $this->container->createInstance($formClassName, $args);
66 1
		$this->container->callInjects($form);
67
68 1
		if ($this->translator instanceof Localization\ITranslator) {
0 ignored issues
show
Bug introduced by
The class Nette\Localization\ITranslator does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
69
			$form->setTranslator($this->translator);
70
		}
71
72 1
		return $form;
73
	}
74
}
75