1<?php
2/**
3 * Copyright since 2007 PrestaShop SA and Contributors
4 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
5 *
6 * NOTICE OF LICENSE
7 *
8 * This source file is subject to the Open Software License (OSL 3.0)
9 * that is bundled with this package in the file LICENSE.md.
10 * It is also available through the world-wide-web at this URL:
11 * https://opensource.org/licenses/OSL-3.0
12 * If you did not receive a copy of the license and are unable to
13 * obtain it through the world-wide-web, please send an email
14 * to license@prestashop.com so we can send you a copy immediately.
15 *
16 * DISCLAIMER
17 *
18 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
19 * versions in the future. If you wish to customize PrestaShop for your
20 * needs please refer to https://devdocs.prestashop.com/ for more information.
21 *
22 * @author    PrestaShop SA and Contributors <contact@prestashop.com>
23 * @copyright Since 2007 PrestaShop SA and Contributors
24 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
25 */
26
27namespace PrestaShop\PrestaShop\Core\Domain\Tax\Command;
28
29use PrestaShop\PrestaShop\Core\Domain\Tax\Exception\TaxConstraintException;
30use PrestaShop\PrestaShop\Core\Domain\Tax\Exception\TaxException;
31use PrestaShop\PrestaShop\Core\Domain\Tax\ValueObject\TaxId;
32
33/**
34 * Toggles tax status
35 */
36class ToggleTaxStatusCommand
37{
38    /**
39     * @var bool
40     */
41    private $expectedStatus;
42
43    /**
44     * @var TaxId
45     */
46    private $taxId;
47
48    /**
49     * @param int $taxId
50     * @param bool $expectedStatus
51     *
52     * @throws TaxException
53     */
54    public function __construct($taxId, $expectedStatus)
55    {
56        $this->assertIsBool($expectedStatus);
57        $this->taxId = new TaxId($taxId);
58        $this->expectedStatus = $expectedStatus;
59    }
60
61    /**
62     * @return bool
63     */
64    public function getExpectedStatus()
65    {
66        return $this->expectedStatus;
67    }
68
69    /**
70     * @return TaxId
71     */
72    public function getTaxId()
73    {
74        return $this->taxId;
75    }
76
77    /**
78     * Validates that value is of type boolean
79     *
80     * @param mixed $value
81     *
82     * @throws TaxConstraintException
83     */
84    private function assertIsBool($value)
85    {
86        if (!is_bool($value)) {
87            throw new TaxConstraintException(sprintf('Status must be of type bool, but given %s', var_export($value, true)), TaxConstraintException::INVALID_STATUS);
88        }
89    }
90}
91