Passed
Push — master ( 376488...b8afb8 )
by Maciej
03:54
created

ChunkSizeCalculator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 13
c 0
b 0
f 0
wmc 2
lcom 0
cbo 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A calculateChunkSize() 0 5 2
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * File: ChunkSizeCalculator.php
6
 *
7
 * @author      Maciej Sławik <[email protected]>
8
 * Github:      https://github.com/maciejslawik
9
 */
10
11
namespace MSlwk\ReactPhpPlayground\Model;
12
13
use MSlwk\ReactPhpPlayground\Api\ChunkSizeCalculatorInterface;
14
15
/**
16
 * Class ChunkSizeCalculator
17
 * @package MSlwk\ReactPhpPlayground\Model
18
 */
19
class ChunkSizeCalculator implements ChunkSizeCalculatorInterface
20
{
21
    /**
22
     * @param array $elements
23
     * @param int $numberOfParts
24
     * @return int
25
     */
26
    public function calculateChunkSize(array $elements, int $numberOfParts): int
27
    {
28
        $numberOfChunks = (int)ceil(count($elements) / $numberOfParts);
29
        return $numberOfChunks > 0 ? $numberOfChunks : 1;
30
    }
31
}
32