Completed
Branch feature/multi-screenshot (3b2450)
by Geza
12:02
created

ScreenshotUploader::upload()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

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 2
eloc 4
nc 2
nop 2
1
<?php
2
3
4
namespace Bex\Behat\ScreenshotExtension\Service;
5
use Bex\Behat\ScreenshotExtension\Driver\ImageDriverInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
8
9
/**
10
 * Short description about the class
11
 *
12
 */
13
class ScreenshotUploader
14
{
15
    /**
16
     * @var OutputInterface
17
     */
18
    private $output;
19
20
    /** @var ImageDriverInterface[] $imageDrivers */
21
    private $imageDrivers;
22
23
    public function __construct(OutputInterface $output, array $imageDrivers)
24
    {
25
        $this->output = $output;
26
        $this->imageDrivers = $imageDrivers;
27
    }
28
29
    public function upload($screenshot, $fileName = 'failure.png')
30
    {
31
        foreach ($this->imageDrivers as $imageDriver) {
32
            $imageUrl = $imageDriver->upload($screenshot, $fileName);
33
            $this->printImageLocation($imageUrl);
34
        }
35
    }
36
37
    /**
38
     * @param string $imageUrl
39
     */
40
    private function printImageLocation($imageUrl)
41
    {
42
        $message = sprintf(
43
            '<comment>Screenshot has been taken. Open image at <error>%s</error></comment>',
44
            $imageUrl
45
        );
46
        $options = $this->output->isDecorated() ? OutputInterface::OUTPUT_NORMAL : OutputInterface::OUTPUT_PLAIN;
47
48
        $this->output->writeln($message, $options);
49
    }
50
}