Completed
Push — master ( 14d2cb...ea1b5f )
by judicael
03:30
created

Entity::createDb()   C

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 5

Duplication

Lines 1
Ratio 11.11 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 1
loc 9
ccs 0
cts 7
cp 0
rs 6.2142
c 0
b 0
f 0
cc 3
eloc 5
nc 4
nop 1
crap 12
1
<?php
2
3
/**
4
 * Batch that create entity
5
 *
6
 * @category  	src
7
 * @package   	src\Batch\Controller
8
 * @author    	Judicaël Paquet <[email protected]>
9
 * @copyright 	Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93)
10
 * @license   	http://www.iscreenway.com/framework/licence.php Tout droit réservé à http://www.iscreenway.com
11
 * @version   	Release: 2.0.0
12
 * @filesource	https://github.com/las93/venus2
13
 * @link      	https://github.com/las93
14
 * @since     	2.0.0
15
 *
16
 * @tutorial    You could launch this Batch in /private/
17
 * 				php bin/console scaffolding -p [portal]
18
 * 				-p [portal] => it's the name where you want add your entities and models
19
 * 				-r [rewrite] => if we force rewrite file
20
 * 					by default, it's Batch
21
 */
22
namespace Venus\src\Batch\Controller;
23
24
use \Venus\core\Config as Config;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Venus\src\Batch\Controller\Config.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
25
use \Attila\Batch\Entity as BatchEntity;
26
use \Attila\Batch\Operation as Operation;
27
use \Venus\src\Batch\common\Controller as Controller;
28
29
/**
30
 * Batch that create entity
31
 *
32
 * @category  	src
33
 * @package   	src\Batch\Controller
34
 * @author    	Judicaël Paquet <[email protected]>
35
 * @copyright 	Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93)
36
 * @license   	http://www.iscreenway.com/framework/licence.php Tout droit réservé à http://www.iscreenway.com
37
 * @version   	Release: 2.0.0
38
 * @filesource	https://github.com/las93/venus2
39
 * @link      	https://github.com/las93
40
 * @since     	2.0.0
41
 */
42
class Entity extends Controller
43
{
44
	/**
45
	 * run the batch to create entity
46
	 * @tutorial bin/console scaffolding
47
	 *
48
	 * @access public
49
	 * @param  array $aOptions options of script
50
	 * @return void
51
	 */
52
	public function runScaffolding(array $aOptions = array())
53
	{
54
	    if (!isset($aOptions['p'])) { $aOptions['p'] = 'Batch'; }
55
	    
56 View Code Duplication
	    if (!isset($aOptions['b'])) { $aOptions['b'] = json_encode(Config::get('Db', $aOptions['p'])); }
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
	    
58
	    $aOptions['g'] = __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.$aOptions['p'].DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'Entity'.DIRECTORY_SEPARATOR;
59
	    $aOptions['h'] = __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.$aOptions['p'].DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'Model'.DIRECTORY_SEPARATOR;
60
	    if (!defined('ENTITY_NAMESPACE')) { define('ENTITY_NAMESPACE', '\Venus\src\\'.$aOptions['p'].'\Entity'); }
61
	    
62
	    if (!defined('MODEL_NAMESPACE')) { define('MODEL_NAMESPACE', '\Venus\src\\'.$aOptions['p'].'\Model'); }
63
	    
64
	    $oBatch = new BatchEntity;
65
	    $oBatch->runScaffolding($aOptions);
66
	}
67
68
    /**
69
     * run the batch to create entity
70
     * @tutorial bin/console scaffolding
71
     *
72
     * @access public
73
     * @param  array $aOptions options of script
74
     * @return void
75
     */
76
    public function createDb(array $aOptions = array())
77
    {
78
        if (!isset($aOptions['p'])) { $aOptions['p'] = 'Batch'; }
79
80 View Code Duplication
        if (!isset($aOptions['b'])) { $aOptions['b'] = json_encode(Config::get('Db', $aOptions['p'])); }
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
81
82
        $oBatch = new Operation;
83
        $oBatch->createDb($aOptions);
84
    }
85
}
86