Completed
Pull Request — master (#36)
by
unknown
11:10
created

AsyncCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 23.08 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 9
loc 39
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getOutputRedirection() 0 3 1
A getShouldUnlockOnCompletion() 0 3 1
A getSendMailOnError() 0 4 1
A getLogger() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace App\Satis\Context;
4
5
use App\Satis\CommandContextInterface;
6
use Monolog\Formatter\LineFormatter;
7
use Monolog\Handler\StreamHandler;
8
use Monolog\Logger;
9
10
/**
11
 * @author Lukas Homza <[email protected]>
12
 */
13
class AsyncCommand implements CommandContextInterface {
14
    /**
15
     * @param string $logFile
16
     * @return string
17
     */
18
    public function getOutputRedirection($logFile) {
19
        return '&> ' . escapeshellarg($logFile);
20
    }
21
22
	/**
23
     * @return string
24
     */
25
    public function getShouldUnlockOnCompletion() {
26
        return ' && php artisan satis:persister:unlock';
27
    }
28
29
    /**
30
     * @param string $email
31
     * @param string $message
32
     * @return string
33
     */
34
    public function getSendMailOnError($email, $message)
35
    {
36
        return '|| echo "'.$message.'" | mail -s "Satis build failed" "'.$email.'"';
37
    }
38
39
    /**
40
     * @return \Monolog\Logger
41
     */
42 View Code Duplication
    public function getLogger() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
        $handler = new StreamHandler(storage_path('logs/builder_async.log'), Logger::DEBUG);
44
        $handler->setFormatter(new LineFormatter(null, null, true, true));
45
46
        $logger = new Logger('AsyncBuildLog');
47
        $logger->pushHandler($handler);
48
49
        return $logger;
50
    }
51
}
52