ChunkableOptions::getChunks()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 4
nop 1
crap 3
1
<?php
0 ignored issues
show
Coding Style introduced by
This file is missing a doc comment.
Loading history...
Coding Style introduced by
The PHP open tag does not have a corresponding PHP close tag
Loading history...
Coding Style introduced by
Filename "ChunkableOptions.php" doesn't match the expected filename "chunkableoptions.php"
Loading history...
2
namespace EddIriarte\Console\Inputs\Traits;
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
4
use EddIriarte\Console\Inputs\Exceptions\IndexOutOfRange;
5
6
7
/**
8
 * Trait ChunkableOptions
9
 * @package EddIriarte\Console\Inputs\Traits
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
10
 * @author Eduardo Iriarte <eddiriarte[at]gmail[dot]com>
0 ignored issues
show
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
11
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
12
trait ChunkableOptions
13
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for trait ChunkableOptions
Loading history...
14
    protected $chunks;
0 ignored issues
show
Coding Style introduced by
Protected member variable "chunks" must contain a leading underscore
Loading history...
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
15
16
    protected $chunkSize = 3;
0 ignored issues
show
Coding Style introduced by
Protected member variable "chunkSize" must contain a leading underscore
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
17
18
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $chunkSize should have a doc-comment as per coding-style.
Loading history...
19
     * @return array
20
     */
21 19
    public function getChunks(int $chunkSize = null): array
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of null please use NULL.
Loading history...
22
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
23 19
        if (!is_null($chunkSize)) {
0 ignored issues
show
Coding Style introduced by
There must be a single space after a NOT operator; 0 found
Loading history...
24 9
            $this->chunkSize = $chunkSize;
25
        }
26
27 19
        if (!isset($this->chunks)) {
0 ignored issues
show
Coding Style introduced by
There must be a single space after a NOT operator; 0 found
Loading history...
28 15
            $this->chunks = array_chunk($this->getOptions(), $this->chunkSize);
0 ignored issues
show
Bug introduced by
It seems like getOptions() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
            $this->chunks = array_chunk($this->/** @scrutinizer ignore-call */ getOptions(), $this->chunkSize);
Loading history...
29
        }
30
31 19
        return $this->chunks;
32
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end getChunks()
Loading history...
33
34
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
35
     * @param int $index
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected "integer" but found "int" for parameter type
Loading history...
36
     * @return array
37
     * @throws EddIriarte\Console\Inputs\Exceptions\IndexOutOfRange
0 ignored issues
show
introduced by
Comment missing for @throws tag in function comment
Loading history...
38
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @throws tag for "IndexOutOfRange" exception
Loading history...
39 2
    public function getChunkAt(int $index): array
40
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
41 2
        if (!empty($this->getChunks()[$index])) {
0 ignored issues
show
Coding Style introduced by
There must be a single space after a NOT operator; 0 found
Loading history...
42 1
            return $this->getChunks()[$index];
43
        }
44
45 1
        throw new IndexOutOfRange($index);
46
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end getChunkAt()
Loading history...
47
48
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
49
     * @return int
0 ignored issues
show
Coding Style introduced by
Expected "integer" but found "int" for function return type
Loading history...
50
     */
51 8
    public function getChunksCount(): int
52
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
53 8
        return count($this->getChunks());
54
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end getChunksCount()
Loading history...
55
56
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
57
     * @param int $rowIndex
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected "integer" but found "int" for parameter type
Loading history...
58
     * @param int $colIndex
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected "integer" but found "int" for parameter type
Loading history...
59
     * @return bool
0 ignored issues
show
Coding Style introduced by
Expected "boolean" but found "bool" for function return type
Loading history...
60
     */
61 12
    public function hasEntryAt(int $rowIndex, int $colIndex): bool
62
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
63 12
        $chunks = $this->getChunks();
64 12
        return array_key_exists($rowIndex, $chunks) && array_key_exists($colIndex, $chunks[$rowIndex]);
0 ignored issues
show
Coding Style introduced by
Boolean operators are not allowed outside of control structure conditions
Loading history...
65
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end hasEntryAt()
Loading history...
66
67
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
68
     * @param int $rowIndex
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected "integer" but found "int" for parameter type
Loading history...
69
     * @param int $colIndex
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected "integer" but found "int" for parameter type
Loading history...
70
     * @return string
71
     * @throws EddIriarte\Console\Inputs\Exceptions\IndexOutOfRange
0 ignored issues
show
introduced by
Comment missing for @throws tag in function comment
Loading history...
72
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @throws tag for "IndexOutOfRange" exception
Loading history...
73 7
    public function getEntryAt(int $rowIndex, int $colIndex): string
74
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
75 7
        if ($this->hasEntryAt($rowIndex, $colIndex)) {
76 6
            return $this->getChunks()[$rowIndex][$colIndex];
77
        }
78
79 1
        throw new IndexOutOfRange("{$rowIndex}:{$colIndex}");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $rowIndex instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $colIndex instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
80
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end getEntryAt()
Loading history...
81
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
82