Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
50.00% covered (danger)
50.00%
3 / 6
CRAP
76.92% covered (warning)
76.92%
10 / 13
Chart
0.00% covered (danger)
0.00%
0 / 1
50.00% covered (danger)
50.00%
3 / 6
7.60
76.92% covered (warning)
76.92%
10 / 13
 __construct
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
7 / 7
 getProviders
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 withHistory
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getFirstProvider
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getGraphSettings
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getType
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
<?php
namespace Alxvng\QATracker\Chart;
use Alxvng\QATracker\DataProvider\Model\AbstractDataSerie;
use RuntimeException;
class Chart
{
    protected array $providers;
    protected bool $withHistory = true;
    protected array $graphSettings;
    protected string $type;
    /**
     * Chart constructor.
     *
     * @param array $config
     * @param array $providersStack
     */
    public function __construct(array $config, array $providersStack)
    {
        $this->type = $config['type'];
        $this->withHistory = $config['withHistory'];
        $this->graphSettings = $config['graphSettings'];
        $this->providers = array_intersect_key($providersStack, array_flip($config['dataSeries']));
        if (empty($this->providers)) {
            throw new RuntimeException('You must define at least one valid data serie for chart.');
        }
    }
    public function getProviders(): array
    {
        return $this->providers;
    }
    public function withHistory(): bool
    {
        return $this->withHistory;
    }
    public function getFirstProvider(): AbstractDataSerie
    {
        $providers = $this->getProviders();
        return reset($providers);
    }
    /**
     * @return array|mixed
     */
    public function getGraphSettings()
    {
        return $this->graphSettings;
    }
    /**
     * @return mixed|string
     */
    public function getType()
    {
        return $this->type;
    }
}