These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * @license MIT, http://opensource.org/licenses/MIT |
||
5 | * @copyright Aimeos (aimeos.org), 2016 |
||
6 | * @package laravel |
||
7 | * @subpackage Base |
||
8 | */ |
||
9 | |||
10 | namespace Aimeos\Shop\Base; |
||
11 | |||
12 | |||
13 | /** |
||
14 | * Service providing the config object |
||
15 | * |
||
16 | * @package laravel |
||
17 | * @subpackage Base |
||
18 | */ |
||
19 | class Config |
||
20 | { |
||
21 | /** |
||
22 | * @var \Aimeos\Shop\Base\Config[] |
||
23 | */ |
||
24 | private $objects = array(); |
||
25 | |||
26 | /** |
||
27 | * @var \Aimeos\Shop\Base\Aimeos |
||
28 | */ |
||
29 | private $aimeos; |
||
30 | |||
31 | /** |
||
32 | * @var \Illuminate\Contracts\Config\Repository |
||
33 | */ |
||
34 | private $config; |
||
35 | |||
36 | |||
37 | /** |
||
38 | * Initializes the object |
||
39 | * |
||
40 | * @param \Illuminate\Contracts\Config\Repository $config Configuration object |
||
41 | * @param \Aimeos\Shop\Base\Aimeos $aimeos Aimeos object |
||
42 | */ |
||
43 | public function __construct( \Illuminate\Contracts\Config\Repository $config, \Aimeos\Shop\Base\Aimeos $aimeos ) |
||
44 | { |
||
45 | $this->aimeos = $aimeos; |
||
46 | $this->config = $config; |
||
47 | } |
||
48 | |||
49 | |||
50 | /** |
||
51 | * Creates a new configuration object. |
||
52 | * |
||
53 | * @param integer $type Configuration type ("frontend" or "backend") |
||
54 | * @return \Aimeos\MW\Config\Iface Configuration object |
||
55 | */ |
||
56 | public function get( $type = 'frontend' ) |
||
57 | { |
||
58 | if( !isset( $this->objects[$type] ) ) |
||
59 | { |
||
60 | $configPaths = $this->aimeos->get()->getConfigPaths(); |
||
61 | $cfgfile = dirname( dirname( dirname( __DIR__ ) ) ) . DIRECTORY_SEPARATOR . 'default.php'; |
||
62 | |||
63 | $config = new \Aimeos\MW\Config\PHPArray( require $cfgfile, $configPaths ); |
||
64 | |||
65 | View Code Duplication | if( $this->config->get( 'shop.apc_enabled', false ) == true ) { |
|
0 ignored issues
–
show
|
|||
66 | $config = new \Aimeos\MW\Config\Decorator\APC( $config, $this->config->get( 'shop.apc_prefix', 'laravel:' ) ); |
||
67 | } |
||
68 | |||
69 | $config = new \Aimeos\MW\Config\Decorator\Memory( $config, $this->config->get( 'shop' ) ); |
||
70 | |||
71 | if( ( $conf = $this->config->get( 'shop.' . $type, array() ) ) !== array() ) { |
||
72 | $config = new \Aimeos\MW\Config\Decorator\Memory( $config, $conf ); |
||
73 | } |
||
74 | |||
75 | $this->objects[$type] = $config; |
||
76 | } |
||
77 | |||
78 | return $this->objects[$type]; |
||
79 | } |
||
80 | } |
||
81 |
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.