Completed
Branch master (1afb45)
by Timothy
04:13
created

BaseCommand::echoBox()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
/**
3
 * Hummingbird Anime Client
4
 *
5
 * An API client for Hummingbird to manage anime and manga watch lists
6
 *
7
 * @package     HummingbirdAnimeClient
8
 * @author      Timothy J. Warren
9
 * @copyright   Copyright (c) 2015 - 2016
10
 * @link        https://github.com/timw4mail/HummingBirdAnimeClient
11
 * @license     MIT
12
 */
13
14
namespace Aviat\AnimeClient\Command;
15
16
use Aura\Session\SessionFactory;
17
use ConsoleKit\Command;
18
use ConsoleKit\Widgets\Box;
19
20
use Aviat\Ion\Di\Container;
21
use Aviat\Ion\Cache\CacheManager;
22
use Aviat\AnimeClient\Config;
23
use Aviat\AnimeClient\AnimeClient;
24
use Aviat\AnimeClient\Auth\HummingbirdAuth;
25
use Aviat\AnimeClient\Model;
26
27
/**
28
 * Base class for console command setup
29
 */
30
class BaseCommand extends Command {
31
	use \Aviat\Ion\Di\ContainerAware;
32
33
	/**
34
	 * Echo text in a box
35
	 *
36
	 * @param string $message
37
	 * @return void
38
	 */
39
	protected function echoBox($message)
40
	{
41
		echo "\n";
42
		$box = new Box($this->getConsole(), $message);
43
		$box->write();
44
		echo "\n";
45
	}
46
47
	/**
48
	 * Setup the Di container
49
	 *
50
	 * @return Container
51
	 */
52
	protected function setupContainer()
0 ignored issues
show
Coding Style introduced by
setupContainer uses the super-global variable $_COOKIE which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
53
	{
54
		$CONF_DIR = __DIR__ . '/../../../../app/config/';
55
		require_once $CONF_DIR . '/base_config.php'; // $base_config
56
57
		$config = AnimeClient::load_toml($CONF_DIR);
58
		$config_array = array_merge($base_config, $config);
0 ignored issues
show
Bug introduced by
The variable $base_config does not exist. Did you mean $config?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
59
60
		$di = function ($config_array) {
61
			$container = new Container();
62
63
			// Create Config Object
64
			$config = new Config($config_array);
65
			$container->set('config', $config);
66
67
			// Create Cache Object
68
			$container->set('cache', new CacheManager($container));
69
70
			// Create session Object
71
			$session = (new SessionFactory())->newInstance($_COOKIE);
72
			$container->set('session', $session);
73
74
			// Models
75
			$container->set('api-model', new Model\API($container));
76
			$container->set('anime-model', new Model\Anime($container));
77
			$container->set('manga-model', new Model\Manga($container));
78
79
			$container->set('auth', new HummingbirdAuth($container));
80
81
			return $container;
82
		};
83
84
		return $di($config_array);
85
	}
86
}