Common   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
c 1
b 0
f 0
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A saveFile() 0 19 3
1
<?php
2
3
namespace TgScraper\Commands;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Logger\ConsoleLogger;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
trait Common
10
{
11
12
    protected function saveFile(
13
        ConsoleLogger $logger,
14
        OutputInterface $output,
15
        string $destination,
16
        string $data,
17
        ?string $prefix = null,
18
        bool $log = true
19
    ): int {
20
        $result = file_put_contents($destination, $data);
21
        if (false === $result) {
22
            $logger->critical($prefix . 'Unable to save file to ' . $destination);
23
            return Command::FAILURE;
24
        }
25
        if ($log) {
26
            $logger->info($prefix . 'Done!');
27
            return Command::SUCCESS;
28
        }
29
        $output->writeln($prefix . 'Done!');
30
        return Command::SUCCESS;
31
    }
32
33
}