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

ScreenshotUploader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 38
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A upload() 0 7 2
A printImageLocation() 0 10 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
}