Completed
Push — master ( 15b9c2...d86504 )
by Philippe
10:35 queued 06:35
created
ChuckFactService/ChuckAPIService.php 1 patch
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -6,119 +6,119 @@
 block discarded – undo
6 6
 
7 7
 class ChuckAPIService
8 8
 {
9
-    /**
10
-     * If user has not its own parameters set, value will be 'Chuck'.
11
-     *
12
-     * @var string
13
-     */
14
-    private $firstName;
15
-
16
-    /**
17
-     * If user has not its own parameters set, value will be 'Norris'.
18
-     *
19
-     * @var string
20
-     */
21
-    private $lastName;
22
-
23
-    /**
24
-     * After n seconds, cancel.
25
-     *
26
-     * @var int
27
-     */
28
-    private $timeout;
29
-
30
-    /**
31
-     * @param string $firstName
32
-     * @param string $lastName
33
-     * @param int    $timeout
34
-     */
35
-    public function __construct($firstName = 'Chuck', $lastName = 'Norris', $timeout = 2)
36
-    {
37
-        $this
38
-            ->setFirstName($firstName)
39
-            ->setLastName($lastName)
40
-            ->setTimeout($timeout)
41
-        ;
42
-    }
43
-
44
-    /**
45
-     * @param string $firstName
46
-     *
47
-     * @return $this
48
-     */
49
-    public function setFirstName($firstName)
50
-    {
51
-        $this->firstName = $firstName;
52
-
53
-        return $this;
54
-    }
55
-
56
-    /**
57
-     * @param string $lastName
58
-     *
59
-     * @return $this
60
-     */
61
-    public function setLastName($lastName)
62
-    {
63
-        $this->lastName = $lastName;
64
-
65
-        return $this;
66
-    }
67
-
68
-    /**
69
-     * @param int $timeout
70
-     *
71
-     * @return $this
72
-     */
73
-    public function setTimeout($timeout)
74
-    {
75
-        $this->timeout = $timeout;
76
-
77
-        return $this;
78
-    }
79
-
80
-    /**
81
-     * Get fact from Internet Chuck Norris Database.
82
-     *
83
-     * @return string
84
-     */
85
-    public function getFact()
86
-    {
87
-        $response = $this->getResponse();
88
-
89
-        //if status is not 200 then return false
90
-        if ($response->getStatusCode() == 200) {
91
-            $datas = json_decode($response->getBody());
92
-
93
-            return html_entity_decode(stripslashes($datas->value->joke));
94
-        }
95
-    }
96
-
97
-    /**
98
-     * @return \Psr\Http\Message\ResponseInterface
99
-     */
100
-    private function getResponse()
101
-    {
102
-        $client = $this->getClient();
103
-
104
-        $response = $client->get('random', [
105
-            'query' => [
106
-                'firstName' => $this->firstName,
107
-                'lastName' => $this->lastName,
108
-            ],
109
-        ]);
110
-
111
-        return $response;
112
-    }
113
-
114
-    /**
115
-     * @return Client
116
-     */
117
-    private function getClient()
118
-    {
119
-        return new Client([
120
-            'base_uri' => 'http://api.icndb.com/jokes/',
121
-            'timeout' => $this->timeout,
122
-        ]);
123
-    }
9
+	/**
10
+	 * If user has not its own parameters set, value will be 'Chuck'.
11
+	 *
12
+	 * @var string
13
+	 */
14
+	private $firstName;
15
+
16
+	/**
17
+	 * If user has not its own parameters set, value will be 'Norris'.
18
+	 *
19
+	 * @var string
20
+	 */
21
+	private $lastName;
22
+
23
+	/**
24
+	 * After n seconds, cancel.
25
+	 *
26
+	 * @var int
27
+	 */
28
+	private $timeout;
29
+
30
+	/**
31
+	 * @param string $firstName
32
+	 * @param string $lastName
33
+	 * @param int    $timeout
34
+	 */
35
+	public function __construct($firstName = 'Chuck', $lastName = 'Norris', $timeout = 2)
36
+	{
37
+		$this
38
+			->setFirstName($firstName)
39
+			->setLastName($lastName)
40
+			->setTimeout($timeout)
41
+		;
42
+	}
43
+
44
+	/**
45
+	 * @param string $firstName
46
+	 *
47
+	 * @return $this
48
+	 */
49
+	public function setFirstName($firstName)
50
+	{
51
+		$this->firstName = $firstName;
52
+
53
+		return $this;
54
+	}
55
+
56
+	/**
57
+	 * @param string $lastName
58
+	 *
59
+	 * @return $this
60
+	 */
61
+	public function setLastName($lastName)
62
+	{
63
+		$this->lastName = $lastName;
64
+
65
+		return $this;
66
+	}
67
+
68
+	/**
69
+	 * @param int $timeout
70
+	 *
71
+	 * @return $this
72
+	 */
73
+	public function setTimeout($timeout)
74
+	{
75
+		$this->timeout = $timeout;
76
+
77
+		return $this;
78
+	}
79
+
80
+	/**
81
+	 * Get fact from Internet Chuck Norris Database.
82
+	 *
83
+	 * @return string
84
+	 */
85
+	public function getFact()
86
+	{
87
+		$response = $this->getResponse();
88
+
89
+		//if status is not 200 then return false
90
+		if ($response->getStatusCode() == 200) {
91
+			$datas = json_decode($response->getBody());
92
+
93
+			return html_entity_decode(stripslashes($datas->value->joke));
94
+		}
95
+	}
96
+
97
+	/**
98
+	 * @return \Psr\Http\Message\ResponseInterface
99
+	 */
100
+	private function getResponse()
101
+	{
102
+		$client = $this->getClient();
103
+
104
+		$response = $client->get('random', [
105
+			'query' => [
106
+				'firstName' => $this->firstName,
107
+				'lastName' => $this->lastName,
108
+			],
109
+		]);
110
+
111
+		return $response;
112
+	}
113
+
114
+	/**
115
+	 * @return Client
116
+	 */
117
+	private function getClient()
118
+	{
119
+		return new Client([
120
+			'base_uri' => 'http://api.icndb.com/jokes/',
121
+			'timeout' => $this->timeout,
122
+		]);
123
+	}
124 124
 }
Please login to merge, or discard this patch.
Command/ChuckCommand.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -9,26 +9,26 @@
 block discarded – undo
9 9
 
10 10
 class ChuckCommand extends ContainerAwareCommand
11 11
 {
12
-    protected function configure()
13
-    {
14
-        $this
15
-            ->setName('chuck:fact')
16
-            ->setDescription('A Chuck Norris Fact everyday keeps the doctor away')
17
-            ->addArgument('firstName', InputArgument::OPTIONAL, 'Replace Chuck by this string', 'Chuck')
18
-            ->addArgument('lastName', InputArgument::OPTIONAL, 'Replace Norris by this string', 'Norris')
19
-        ;
20
-    }
12
+	protected function configure()
13
+	{
14
+		$this
15
+			->setName('chuck:fact')
16
+			->setDescription('A Chuck Norris Fact everyday keeps the doctor away')
17
+			->addArgument('firstName', InputArgument::OPTIONAL, 'Replace Chuck by this string', 'Chuck')
18
+			->addArgument('lastName', InputArgument::OPTIONAL, 'Replace Norris by this string', 'Norris')
19
+		;
20
+	}
21 21
 
22
-    protected function execute(InputInterface $input, OutputInterface $output)
23
-    {
24
-        $fact = $this->getContainer()->get('kk_labs_chuck_console.fact_service')
25
-            ->setFirstName($input->getArgument('firstName'))
26
-            ->setLastName($input->getArgument('lastName'))
27
-            ->getFact()
28
-        ;
22
+	protected function execute(InputInterface $input, OutputInterface $output)
23
+	{
24
+		$fact = $this->getContainer()->get('kk_labs_chuck_console.fact_service')
25
+			->setFirstName($input->getArgument('firstName'))
26
+			->setLastName($input->getArgument('lastName'))
27
+			->getFact()
28
+		;
29 29
 
30
-        if ($fact) {
31
-            $output->writeln($fact);
32
-        }
33
-    }
30
+		if ($fact) {
31
+			$output->writeln($fact);
32
+		}
33
+	}
34 34
 }
Please login to merge, or discard this patch.
DependencyInjection/Configuration.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -12,26 +12,26 @@
 block discarded – undo
12 12
  */
13 13
 class Configuration implements ConfigurationInterface
14 14
 {
15
-    /**
16
-     * {@inheritdoc}
17
-     */
18
-    public function getConfigTreeBuilder()
19
-    {
20
-        $treeBuilder = new TreeBuilder();
21
-        $rootNode = $treeBuilder->root('kk_labs_chuck_console');
15
+	/**
16
+	 * {@inheritdoc}
17
+	 */
18
+	public function getConfigTreeBuilder()
19
+	{
20
+		$treeBuilder = new TreeBuilder();
21
+		$rootNode = $treeBuilder->root('kk_labs_chuck_console');
22 22
 
23
-        $rootNode
24
-            ->children()
25
-                ->arrayNode('who')
26
-                    ->addDefaultsIfNotSet()
27
-                        ->children()
28
-                            ->scalarNode('first_name')->defaultValue('Chuck')->end()
29
-                            ->scalarNode('last_name')->defaultValue('Norris')->end()
30
-                        ->end()
31
-                    ->end()//who
32
-                ->scalarNode('timeout')->defaultValue(10)->end()
33
-            ->end();
23
+		$rootNode
24
+			->children()
25
+				->arrayNode('who')
26
+					->addDefaultsIfNotSet()
27
+						->children()
28
+							->scalarNode('first_name')->defaultValue('Chuck')->end()
29
+							->scalarNode('last_name')->defaultValue('Norris')->end()
30
+						->end()
31
+					->end()//who
32
+				->scalarNode('timeout')->defaultValue(10)->end()
33
+			->end();
34 34
 
35
-        return $treeBuilder;
36
-    }
35
+		return $treeBuilder;
36
+	}
37 37
 }
Please login to merge, or discard this patch.
DependencyInjection/KKLabsChuckConsoleExtension.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -14,19 +14,19 @@
 block discarded – undo
14 14
  */
15 15
 class KKLabsChuckConsoleExtension extends Extension
16 16
 {
17
-    /**
18
-     * {@inheritdoc}
19
-     */
20
-    public function load(array $configs, ContainerBuilder $container)
21
-    {
22
-        $configuration = new Configuration();
23
-        $config = $this->processConfiguration($configuration, $configs);
17
+	/**
18
+	 * {@inheritdoc}
19
+	 */
20
+	public function load(array $configs, ContainerBuilder $container)
21
+	{
22
+		$configuration = new Configuration();
23
+		$config = $this->processConfiguration($configuration, $configs);
24 24
 
25
-        $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
26
-        $loader->load('services.xml');
25
+		$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
26
+		$loader->load('services.xml');
27 27
 
28
-        $container->setParameter('who.first_name', $config['who']['first_name']);
29
-        $container->setParameter('who.last_name', $config['who']['last_name']);
30
-        $container->setParameter('timeout', $config['timeout']);
31
-    }
28
+		$container->setParameter('who.first_name', $config['who']['first_name']);
29
+		$container->setParameter('who.last_name', $config['who']['last_name']);
30
+		$container->setParameter('timeout', $config['timeout']);
31
+	}
32 32
 }
Please login to merge, or discard this patch.
EventListener/ConsoleTerminateListener.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -8,17 +8,17 @@
 block discarded – undo
8 8
 
9 9
 class ConsoleTerminateListener
10 10
 {
11
-    private $chuckApiService;
11
+	private $chuckApiService;
12 12
 
13
-    public function __construct(ChuckAPIService $chuckAPIService)
14
-    {
15
-        $this->chuckApiService = $chuckAPIService;
16
-    }
13
+	public function __construct(ChuckAPIService $chuckAPIService)
14
+	{
15
+		$this->chuckApiService = $chuckAPIService;
16
+	}
17 17
 
18
-    public function onConsoleTerminate(ConsoleTerminateEvent $event)
19
-    {
20
-        if (!$event->getCommand() instanceof ChuckCommand && $fact = $this->chuckApiService->getFact()) {
21
-            $event->getOutput()->writeln($fact);
22
-        }
23
-    }
18
+	public function onConsoleTerminate(ConsoleTerminateEvent $event)
19
+	{
20
+		if (!$event->getCommand() instanceof ChuckCommand && $fact = $this->chuckApiService->getFact()) {
21
+			$event->getOutput()->writeln($fact);
22
+		}
23
+	}
24 24
 }
Please login to merge, or discard this patch.
Tests/ChuckFactService/ChuckFactServiceTest.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -8,68 +8,68 @@
 block discarded – undo
8 8
 
9 9
 class ChuckFactServiceTest extends \PHPUnit_Framework_TestCase
10 10
 {
11
-    /**
12
-     * @var ContainerInterface
13
-     */
14
-    private $container;
11
+	/**
12
+	 * @var ContainerInterface
13
+	 */
14
+	private $container;
15 15
 
16
-    protected function setUp()
17
-    {
18
-        $kernel = new AppKernel('test', true);
19
-        $kernel->boot();
16
+	protected function setUp()
17
+	{
18
+		$kernel = new AppKernel('test', true);
19
+		$kernel->boot();
20 20
 
21
-        $this->randomFirstName = substr(str_shuffle(MD5(microtime())), 0, 10);
22
-        $this->randomLastName = substr(str_shuffle(MD5(microtime())), 0, 10);
21
+		$this->randomFirstName = substr(str_shuffle(MD5(microtime())), 0, 10);
22
+		$this->randomLastName = substr(str_shuffle(MD5(microtime())), 0, 10);
23 23
 
24
-        $this->container = $kernel->getContainer();
25
-    }
24
+		$this->container = $kernel->getContainer();
25
+	}
26 26
 
27
-    public function testServiceIsDefinedInContainer()
28
-    {
29
-        $service = $this->container->get('kk_labs_chuck_console.fact_service');
27
+	public function testServiceIsDefinedInContainer()
28
+	{
29
+		$service = $this->container->get('kk_labs_chuck_console.fact_service');
30 30
 
31
-        $this->assertInstanceOf('KK\Labs\ChuckConsoleBundle\ChuckFactService\ChuckAPIService', $service);
32
-    }
31
+		$this->assertInstanceOf('KK\Labs\ChuckConsoleBundle\ChuckFactService\ChuckAPIService', $service);
32
+	}
33 33
 
34
-    public function testGetCustomFact()
35
-    {
36
-        $this->assertRegExp(
37
-            "/$this->randomFirstName|$this->randomLastName/",
38
-            $this->getFacts($this->randomFirstName, $this->randomLastName)
39
-        );
40
-    }
34
+	public function testGetCustomFact()
35
+	{
36
+		$this->assertRegExp(
37
+			"/$this->randomFirstName|$this->randomLastName/",
38
+			$this->getFacts($this->randomFirstName, $this->randomLastName)
39
+		);
40
+	}
41 41
 
42
-    public function testGetChuckFact()
43
-    {
44
-        $this->assertRegExp('/Chuck|Norris/', $this->getFacts());
45
-    }
42
+	public function testGetChuckFact()
43
+	{
44
+		$this->assertRegExp('/Chuck|Norris/', $this->getFacts());
45
+	}
46 46
 
47
-    /**
48
-     * @param string $firstName
49
-     * @param string $lastName
50
-     *
51
-     * @return string
52
-     */
53
-    private function getFacts($firstName = 'Chuck', $lastName = 'Norris')
54
-    {
55
-        $chuckService = $this->getChuckService($firstName, $lastName);
47
+	/**
48
+	 * @param string $firstName
49
+	 * @param string $lastName
50
+	 *
51
+	 * @return string
52
+	 */
53
+	private function getFacts($firstName = 'Chuck', $lastName = 'Norris')
54
+	{
55
+		$chuckService = $this->getChuckService($firstName, $lastName);
56 56
 
57
-        $facts = '';
58
-        for ($i = 0; $i < 5; ++$i) {
59
-            $facts .= $chuckService->getFact();
60
-        }
57
+		$facts = '';
58
+		for ($i = 0; $i < 5; ++$i) {
59
+			$facts .= $chuckService->getFact();
60
+		}
61 61
 
62
-        return $facts;
63
-    }
62
+		return $facts;
63
+	}
64 64
 
65
-    /**
66
-     * @param string $firstName
67
-     * @param string $lastName
68
-     *
69
-     * @return ChuckAPIService
70
-     */
71
-    private function getChuckService($firstName = 'Chuck', $lastName = 'Norris')
72
-    {
73
-        return new ChuckAPIService($firstName, $lastName, 5);
74
-    }
65
+	/**
66
+	 * @param string $firstName
67
+	 * @param string $lastName
68
+	 *
69
+	 * @return ChuckAPIService
70
+	 */
71
+	private function getChuckService($firstName = 'Chuck', $lastName = 'Norris')
72
+	{
73
+		return new ChuckAPIService($firstName, $lastName, 5);
74
+	}
75 75
 }
Please login to merge, or discard this patch.
Tests/Command/ChuckCommandTest.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -9,35 +9,35 @@
 block discarded – undo
9 9
 
10 10
 class ChuckCommandTest extends \PHPUnit_Framework_TestCase
11 11
 {
12
-    public function testExecute()
13
-    {
14
-        $firstName = substr(str_shuffle(MD5(microtime())), 0, 10);
15
-        $lastName = substr(str_shuffle(MD5(microtime())), 0, 10);
16
-
17
-        $application = new Application();
18
-        $application->add(new ChuckCommand());
19
-
20
-        $command = $application->find('chuck:fact');
21
-        $command->setContainer($this->getMockContainer());
22
-        $commandTester = new CommandTester($command);
23
-        $commandTester->execute(array(
24
-            'command' => $command->getName(),
25
-            'firstName' => $firstName,
26
-            'lastName' => $lastName,
27
-        ));
28
-
29
-        $this->assertRegExp("/$firstName|$lastName/", $commandTester->getDisplay());
30
-    }
31
-
32
-    protected function getMockContainer()
33
-    {
34
-        $mockContainer = $this->getMock('Symfony\Component\DependencyInjection\Container');
35
-        $mockContainer
36
-            ->expects($this->once())
37
-            ->method('get')
38
-            ->with('kk_labs_chuck_console.fact_service')
39
-            ->willReturn(new ChuckAPIService());
40
-
41
-        return $mockContainer;
42
-    }
12
+	public function testExecute()
13
+	{
14
+		$firstName = substr(str_shuffle(MD5(microtime())), 0, 10);
15
+		$lastName = substr(str_shuffle(MD5(microtime())), 0, 10);
16
+
17
+		$application = new Application();
18
+		$application->add(new ChuckCommand());
19
+
20
+		$command = $application->find('chuck:fact');
21
+		$command->setContainer($this->getMockContainer());
22
+		$commandTester = new CommandTester($command);
23
+		$commandTester->execute(array(
24
+			'command' => $command->getName(),
25
+			'firstName' => $firstName,
26
+			'lastName' => $lastName,
27
+		));
28
+
29
+		$this->assertRegExp("/$firstName|$lastName/", $commandTester->getDisplay());
30
+	}
31
+
32
+	protected function getMockContainer()
33
+	{
34
+		$mockContainer = $this->getMock('Symfony\Component\DependencyInjection\Container');
35
+		$mockContainer
36
+			->expects($this->once())
37
+			->method('get')
38
+			->with('kk_labs_chuck_console.fact_service')
39
+			->willReturn(new ChuckAPIService());
40
+
41
+		return $mockContainer;
42
+	}
43 43
 }
Please login to merge, or discard this patch.
Tests/Fixtures/app/AppKernel.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -7,41 +7,41 @@
 block discarded – undo
7 7
 
8 8
 class AppKernel extends Kernel
9 9
 {
10
-    public function registerBundles()
11
-    {
12
-        return array(
13
-            new \KK\Labs\ChuckConsoleBundle\KKLabsChuckConsoleBundle(),
14
-        );
15
-    }
16
-
17
-    public function registerContainerConfiguration(LoaderInterface $loader)
18
-    {
19
-        $loader->load(__DIR__.'/config/config_test.yml');
20
-    }
21
-
22
-    /**
23
-     * @return string
24
-     */
25
-    public function getCacheDir()
26
-    {
27
-        $cacheDir = sys_get_temp_dir().'/cache';
28
-        if (!is_dir($cacheDir)) {
29
-            mkdir($cacheDir, 0777, true);
30
-        }
31
-
32
-        return $cacheDir;
33
-    }
34
-
35
-    /**
36
-     * @return string
37
-     */
38
-    public function getLogDir()
39
-    {
40
-        $logDir = sys_get_temp_dir().'/logs';
41
-        if (!is_dir($logDir)) {
42
-            mkdir($logDir, 0777, true);
43
-        }
44
-
45
-        return $logDir;
46
-    }
10
+	public function registerBundles()
11
+	{
12
+		return array(
13
+			new \KK\Labs\ChuckConsoleBundle\KKLabsChuckConsoleBundle(),
14
+		);
15
+	}
16
+
17
+	public function registerContainerConfiguration(LoaderInterface $loader)
18
+	{
19
+		$loader->load(__DIR__.'/config/config_test.yml');
20
+	}
21
+
22
+	/**
23
+	 * @return string
24
+	 */
25
+	public function getCacheDir()
26
+	{
27
+		$cacheDir = sys_get_temp_dir().'/cache';
28
+		if (!is_dir($cacheDir)) {
29
+			mkdir($cacheDir, 0777, true);
30
+		}
31
+
32
+		return $cacheDir;
33
+	}
34
+
35
+	/**
36
+	 * @return string
37
+	 */
38
+	public function getLogDir()
39
+	{
40
+		$logDir = sys_get_temp_dir().'/logs';
41
+		if (!is_dir($logDir)) {
42
+			mkdir($logDir, 0777, true);
43
+		}
44
+
45
+		return $logDir;
46
+	}
47 47
 }
Please login to merge, or discard this patch.
Tests/bootstrap.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (!is_file($autoloadFile = __DIR__.'/../vendor/autoload.php')) {
4
-    throw new \LogicException('Could not find autoload.php in vendor/. Did you run "composer install --dev"?');
4
+	throw new \LogicException('Could not find autoload.php in vendor/. Did you run "composer install --dev"?');
5 5
 }
6 6
 
7 7
 require $autoloadFile;
Please login to merge, or discard this patch.