public function addLocation(
        $id,
        $name,
        $code,
        $type,
        LocationInterface $parent = null
    ) {
        $location = isset($this->locations[$id])
            ? $this->locations[$id]
            : $this
                ->locationFactory
                ->create()
                ->setId($id)
                ->setName($name)
                ->setCode($code)
                ->setType($type);

        if ($parent instanceof LocationInterface) {
            $location->addParent($parent);
        }

        $this->locations[$id] = $location;

        return $location;
    }