<?php

    protected function getAndCreateFolder(string $folderPath): Folder
    {
        if ($this->storage->hasFolder($folderPath)) {
            return $this->storage->getFolder($folderPath);
        }

        $folder = $this->storage->getRootLevelFolder(false);
        $parts  = explode('/', $folderPath);
        foreach ($parts as $part) {
            if (!$this->storage->hasFolderInFolder($part, $folder)) {
                $folder = $this->storage->createFolder($part, $folder);
            } else {
                $folder = $this->storage->getFolderInFolder($part, $folder);
            }
        }

        return $folder;
    }
