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

ChunkSizeCalculator::calculateChunkSize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
rs 10
cc 2
nc 2
nop 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