Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00%
1 / 1
100.00%
11 / 11
CRAP
100.00%
28 / 28
Company
100.00%
1 / 1
100.00%
11 / 11
14
100.00%
28 / 28
 __construct($name = null)
100.00%
1 / 1
2
100.00%
3 / 3
 addApp($app)
100.00%
1 / 1
1
100.00%
3 / 3
 addApps($apps)
100.00%
1 / 1
1
100.00%
2 / 2
 getApps()
100.00%
1 / 1
1
100.00%
1 / 1
 addBundle($bundle)
100.00%
1 / 1
1
100.00%
2 / 2
 addBundles($bundles)
100.00%
1 / 1
1
100.00%
2 / 2
 getName()
100.00%
1 / 1
2
100.00%
3 / 3
 setName($name)
100.00%
1 / 1
2
100.00%
4 / 4
 getCostPerMonth()
100.00%
1 / 1
1
100.00%
2 / 2
 anonymous function ($key, $app)
100.00%
1 / 1
1
100.00%
4 / 4
 getCostPerYear()
100.00%
1 / 1
1
100.00%
1 / 1
<?php
namespace TriNetAssess;
/**
 * Class Company
 *
 * @package TriNetAssess
 */
class Company implements CostCalculationsInterface
{
    /**
     * The Apps applied to the Company
     *
     * @var App[] $apps
     */
    protected $apps = [];
    /**
     * The Company's name
     *
     * @var string $name
     */
    protected $name;
    /**
     * Company constructor.
     *
     * @param string $name the Company's name
     *
     * @throws \DomainException
     */
    public function __construct($name = null)
    {
        if (null !== $name) {
            $this->setName($name);
        }
    }
    /**
     * Add an App to the Company
     *
     * @param App $app the App to apply to the Company
     *
     * @return App[]
     */
    public function addApp($app)
    {
        $this->apps[] = $app;
        $this->apps = array_map('unserialize', array_unique(array_map('serialize', $this->apps)));
        return $this->apps;
    }
    /**
     * Add multiple Apps to the Company
     *
     * @param App[] $apps the Apps to apply to the Company
     *
     * @return App[]
     */
    public function addApps($apps)
    {
        array_walk($apps, [$this, 'addApp']);
        return $this->apps;
    }
    /**
     * Get the Apps applied to the Company
     *
     * @return App[]
     */
    public function getApps()
    {
        return $this->apps;
    }
    /**
     * Add a Bundle to the Company
     *
     * @param Bundle $bundle the Bundle to apply to the Company
     *
     * @return App[]
     */
    public function addBundle($bundle)
    {
        $this->addApps($bundle->getApps());
        return $this->apps;
    }
    /**
     * Add multiple Bundles to a company
     *
     * @param Bundle[] $bundles the Bundles to apply to the Company
     *
     * @return App[]
     */
    public function addBundles($bundles)
    {
        array_walk($bundles, [$this, 'addBundle']);
        return $this->apps;
    }
    /**
     * Get the Company's name
     *
     * @return string the Company's name
     * @throws \DomainException
     */
    public function getName()
    {
        if (!is_string($this->name)) {
            throw new \DomainException('Company name must be a string');
        }
        return $this->name;
    }
    /**
     * Set the Company's name
     *
     * @param string $name the Company's name
     *
     * @return string the Company's name
     * @throws \DomainException
     */
    public function setName($name)
    {
        if (!is_string($name)) {
            throw new \DomainException('Company name must be a string');
        }
        $this->name = $name;
        return $this->name;
    }
    /**
     * Get the total cost per month
     *
     * @return float total cost per month
     */
    public function getCostPerMonth()
    {
        $cost = array_reduce(
            $this->getApps(),
            function ($key, $app) {
                $key+= $app->getCostPerMonth();
                return $key;
            }
        );
        return $cost;
    }
    /**
     * Get the total cost per year
     *
     * @return float total cost per year
     */
    public function getCostPerYear()
    {
        return 12 * $this->getCostPerMonth();
    }