Completed
Push — feature/0.7.0 ( 887737...ad3584 )
by Ryuichi
02:53
created

ConsoleOutputStream   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 33
Duplicated Lines 27.27 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 1
cbo 1
dl 9
loc 33
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B write() 9 15 7
A close() 0 4 1
A flush() 0 4 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
namespace WebStream\IO;
3
4
/**
5
 * ConsoleOutputStream
6
 * @author Ryuichi TANAKA.
7
 * @since 2016/02/27
8
 * @version 0.7
9
 */
10
class ConsoleOutputStream extends OutputStream
11
{
12
    public function __construct()
13
    {
14
        parent::__construct("");
15
    }
16
17
    public function write($buf, int $off = null, int $len = null)
18
    {
19
        $data = null;
0 ignored issues
show
Unused Code introduced by
$data is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
20 View Code Duplication
        if ($off === null && $len === null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
21
            $data = $buf;
22
        } elseif ($off !== null && $len === null) {
23
            $data = substr($buf, $off);
24
        } elseif ($off === null && $len !== null) {
25
            $data = substr($buf, 0, $len);
26
        } else {
27
            $data = substr($buf, $off, $len);
28
        }
29
30
        $this->stream .= $data;
31
    }
32
33
    public function close()
34
    {
35
        $this->stream = null;
36
    }
37
38
    public function flush()
39
    {
40
        echo $this->stream;
41
    }
42
}
43