Failed Conditions
Pull Request — master (#12)
by Tibor
03:44
created

ScreenshotUploader::printImageLocation()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace Bex\Behat\ScreenshotExtension\Service;
4
5
use Bex\Behat\ScreenshotExtension\Driver\ImageDriverInterface;
6
use Bex\Behat\ScreenshotExtension\ServiceContainer\Config;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
class ScreenshotUploader
10
{
11
    /**
12
     * @var OutputInterface
13
     */
14
    private $output;
15
16
    /**
17
     * @var Config
18
     */
19
    private $config;
20
21
    /**
22
     * @param OutputInterface $output
23
     * @param Config          $config
24
     */
25
    public function __construct(OutputInterface $output, Config $config)
26
    {
27
        $this->output = $output;
28
        $this->config = $config;
29
    }
30
31
    /**
32
     * @param  string $screenshot
33
     * @param  string $fileName
34
     */
35
    public function upload($screenshot, $fileName = 'failure.png')
36
    {
37
        foreach ($this->config->getImageDrivers() as $imageDriver) {
38
            $imageUrl = $imageDriver->upload($screenshot, $fileName);
39
            $this->printImageLocation($imageUrl);
40
        }
41
    }
42
43
    /**
44
     * @param string $imageUrl
45
     */
46
    private function printImageLocation($imageUrl)
47
    {
48
        $this->output->writeln(
49
            sprintf('<comment>Screenshot has been taken. Open image at <error>%s</error></comment>', $imageUrl),
50
            $this->output->isDecorated() ? OutputInterface::OUTPUT_NORMAL : OutputInterface::OUTPUT_PLAIN
51
        );
52
    }
53
}
54