Install/Installer.php
public function installTaxes($codes = ['US'])
    {
        $codes = (array)$codes;

        if (empty($codes)) {
            return;
        }

        $taxRepository = $this->manager->getRepository(Tax::class);

        foreach ($codes as $code) {
            $path = __DIR__ . '/data/' . $code . '_taxes.yml';
            if (!(file_exists($path) && is_readable($path))) {
                call_user_func($this->log, 'Taxes data', 'not found');
                continue;
            }

            $data = Yaml::parse(file_get_contents($path));
            if (!is_array($data) || empty($data)) {
                continue;
            }

            $country = $this
                ->manager
                ->getRepository(Country::class)
                ->findOneBy(['code' => $code]);
            if (null === $country) {
                continue;
            }

            foreach ($data as $datum) {
                $name = $datum['name'];
                $result = 'already exists';

                if (null === $taxRepository->findOneBy(['name' => $name])) {
                    $tax = new Tax();
                    $tax
                        ->setName($name)
                        ->setRate($datum['rate'])
                        ->setCountry($country);

                    $this->manager->persist($tax);

                    $result = 'done';
                }

                call_user_func($this->log, $name, $result);
            }
        }

        $this->manager->flush();
    }
public function installTaxes($codes = ['US'])
    {
        $codes = (array)$codes;

        if (empty($codes)) {
            return;
        }

        $taxRepository = $this->manager->getRepository(Tax::class);

        foreach ($codes as $code) {
            $path = __DIR__ . '/data/' . $code . '_taxes.yml';
            if (!(file_exists($path) && is_readable($path))) {
                call_user_func($this->log, 'Taxes data', 'not found');
                continue;
            }

            $data = Yaml::parse(file_get_contents($path));
            if (!is_array($data) || empty($data)) {
                continue;
            }

            $country = $this
                ->manager
                ->getRepository(Country::class)
                ->findOneBy(['code' => $code]);
            if (null === $country) {
                continue;
            }

            foreach ($data as $datum) {
                $name = $datum['name'];
                $result = 'already exists';

                if (null === $taxRepository->findOneBy(['name' => $name])) {
                    $tax = new Tax();
                    $tax
                        ->setName($name)
                        ->setRate($datum['rate'])
                        ->setCountry($country);

                    $this->manager->persist($tax);

                    $result = 'done';
                }

                call_user_func($this->log, $name, $result);
            }
        }

        $this->manager->flush();
    }
Installs the taxes for the given country codes.

@param array $codes The country codes to load the taxes for