• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jojo1981 / data-resolver / 170

pending completion
170

cron

travis-ci-com

jojo1981
Fix error: `Argument 1 passed to Jojo1981\DataResolver\Resolver\Context::pushPathPart() must be of the type string, int given, called in...`

1 of 1 new or added line in 1 file covered. (100.0%)

454 of 868 relevant lines covered (52.3%)

5.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

58.33
/src/Extractor/SumExtractor.php
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of the jojo1981/data-resolver package
4
 *
5
 * Copyright (c) 2020 Joost Nijhuis <jnijhuis81@gmail.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed in the root of the source code
9
 */
10
namespace Jojo1981\DataResolver\Extractor;
11

12
use Jojo1981\DataResolver\Extractor\Exception\ExtractorException;
13
use Jojo1981\DataResolver\Handler\Exception\HandlerException;
14
use Jojo1981\DataResolver\Handler\SequenceHandlerInterface;
15
use Jojo1981\DataResolver\Resolver\Context;
16
use function get_class;
17
use function is_numeric;
18
use function sprintf;
19

20
/**
21
 * @package Jojo1981\DataResolver\Extractor
22
 */
23
final class SumExtractor extends AbstractSequenceExtractor
24
{
25
    /** @var SequenceHandlerInterface */
26
    private SequenceHandlerInterface $sequenceHandler;
27

28
    /**
29
     * @param SequenceHandlerInterface $sequenceHandler
30
     */
31
    public function __construct(SequenceHandlerInterface $sequenceHandler)
32
    {
33
        $this->sequenceHandler = $sequenceHandler;
4✔
34
    }
35

36
    /**
37
     * @return SequenceHandlerInterface
38
     */
39
    protected function getSequenceHandler(): SequenceHandlerInterface
40
    {
41
        return $this->sequenceHandler;
4✔
42
    }
43

44
    /**
45
     * @param Context $context
46
     * @return float
47
     * @throws HandlerException
48
     * @throws ExtractorException
49
     */
50
    protected function performExtract(Context $context): float
51
    {
52
        $sum = 0.0;
2✔
53
        foreach ($this->sequenceHandler->getIterator($context->getData()) as $item) {
2✔
54
            if (!is_numeric($item)) {
2✔
55
                throw new ExtractorException(sprintf(
×
56
                    'Found a NOT numeric item. Could not extract data with `%s` at path: `%s`',
×
57
                    get_class($this),
×
58
                    $context->getPath()
×
59
                ));
×
60
            }
61

62
            $sum += (float)$item;
2✔
63
        }
64

65
        return $sum;
2✔
66
    }
67
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc