@param VolumeInterface $volume
@param FolderInterface $folder

@return CalculatedSize
13528
public function calculate(VolumeInterface $volume, FolderInterface $folder = null)
    {
        if (null === $folder) {
            $folder = $volume->findRootFolder();
        }

        $size = 0;
        $numFiles = 0;

        foreach ($volume->findFilesByFolder($folder) as $file) {
            $size += $file->getSize();
            ++$numFiles;
        }

        $calculatedsize = new CalculatedSize($size, 1, $numFiles);

        foreach ($volume->findFoldersByParentFolder($folder) as $subFolder) {
            $subCalculatedSize = $this->calculate($volume, $subFolder);
            $calculatedsize->merge($subCalculatedSize);
        }

        return $calculatedsize;
    }
851117
private function getSizeByFixedHeight(ImageInterface $image, $newHeight)
    {
        $box   = $image->getSize();
        $ratio = $box->getWidth() / $box->getHeight();

        $newWidth = $newHeight * $ratio;

        return $newWidth;
    }
1070850
protected function execute(InputInterface $input, OutputInterface $output) : ?int
    {
        $loggerHelper = new LoggerHelper();
        $logger       = $loggerHelper->create($output);

        /** @var string $resources */
        $resources = $input->getOption('resources');

        $divisionsResourcePath = $resources . '/user-agents';

        $logger->info('Resource folder: ' . $resources);

        $schemaStorage   = new SchemaStorage();
        $schemaValidator = new Validator\SchemaValidator(
            new \JsonSchema\Validator(
                new Constraints\Factory(
                    $schemaStorage,
                    $schemaStorage->getUriRetriever()
                )
            )
        );

        $schemaUri = 'file://' . realpath(__DIR__ . '/../../../schema/divisions.json');

        try {
            /** @var \stdClass $schema */
            $schema = $schemaStorage->getSchema($schemaUri);
        } catch (\Throwable $exception) {
            $logger->critical('the schema file is invalid');

            return 1;
        }
        $failed = false;

        $jsonParser = new JsonParser();

        $finder = new Finder();
        $finder->files();
        $finder->name('*.json');
        $finder->ignoreDotFiles(true);
        $finder->ignoreVCS(true);
        $finder->sortByName();
        $finder->ignoreUnreadableDirs();
        $finder->in($divisionsResourcePath);

        foreach ($finder as $file) {
            /* @var \Symfony\Component\Finder\SplFileInfo $file */
            $logger->info('read source file ' . $file->getPathname());

            try {
                $json = $file->getContents();
            } catch (\RuntimeException $e) {
                $logger->critical(new \Exception(sprintf('could not read file "%s"', $file->getPathname()), 0, $e));

                continue;
            }

            try {
                $decoded = $jsonParser->parse($json, JsonParser::DETECT_KEY_CONFLICTS);

                if (!$schemaValidator->isValid($decoded, $schema)) {
                    $logger->critical(sprintf('file "%s" is not valid', $file->getPathname()));
                    $failed = true;
                }
            } catch (ParsingException $e) {
                $logger->critical('File "' . $file->getPathname() . '" had invalid JSON. [JSON error: ' . json_last_error_msg() . ']');
                $failed = true;
            }
        }

        if (!$failed) {
            $output->writeln('the division files are valid');
        }

        return (int) $failed;
    }
342976
public function moveAction(Request $request)
    {
        $volumeId = $request->get('site_id');
        $targetId = $request->get('target_id');
        $sourceId = $request->get('source_id');

        $volume = $this->getVolume($volumeId);
        $folder = $volume->findFolder($sourceId);
        $targetFolder = $volume->findFolder($targetId);

        $volume->moveFolder($folder, $targetFolder, $this->getUser()->getId());

        return new ResultResponse(true);
    }
136573
public function setFontSize(int $size): PdfInterface
    {
        $this->fontSize = (int) $size;
        $this->mpdf->SetDefaultFontSize($this->fontSize);

        return $this;
    }
831883
private function recurseFolders(VolumeInterface $volume, ExtendedFolderInterface $folder)
    {
        $data = array();

        foreach ($volume->findFoldersByParentFolder($folder) as $subFolder) {
            if (!$this->isGranted('FOLDER_READ', $subFolder)) {
                // TODO: uncomment
                //continue;
            }

            $tmp = array(
                'id' => $subFolder->getId(),
                'site_id' => $volume->getId(),
                'text' => $subFolder->getName(),
                'leaf' => false, //!$subFolder->hasSubFolders(),
                'numChilds' => $volume->countFoldersByParentFolder($subFolder),
                'allowDrop' => true,
                'children' => $this->recurseFolders($volume, $subFolder),
            );

            if (!$tmp['numChilds']) {
                $tmp['expanded'] = true;
                $tmp['children'] = [];
            }

            $data[] = $tmp;
        }

        return $data;
    }
626818
public function deletePhysicalFolder(FolderInterface $folder, $userId)
    {
        $filesystem = new Filesystem();

        $physicalPath = $this->getVolume()->getRootDir().$folder->getPath();

        if ($filesystem->exists($physicalPath) && !is_dir($physicalPath)) {
            throw new IOException('Delete folder failed, not a folder.');
        }

        if ($filesystem->exists($physicalPath) && !is_writable($physicalPath)) {
            throw new NotWritableException('Delete folder failed.');
        }

        foreach ($this->findFoldersByParentFolder($folder) as $subFolder) {
            $this->deletePhysicalFolder($subFolder, $userId);
        }

        foreach ($this->findFilesByFolder($folder) as $file) {
            $this->deleteFile($file, $userId);
        }

        if (is_file($physicalPath)) {
            $filesystem->remove($physicalPath);
        }

        $folder->setId(null);
    }
1133878
public static function dirsize($dir, $createifmissing = false) {
		$dirsize = 0;
		if (!file_exists($dir)) {
			if ($createifmissing === true) {
				mkdir($dir);
				return 0;
			}
			throw new \Exception('Directory does not exist!', 400);
		}

		$dir_info = scandir($dir);

		if ($dir{(mb_strlen($dir) - 1)} !== '/') {
			$dir .= '/';
		}

		clearstatcache();
		foreach ($dir_info as $i => $member) {
			if ($member === '.' || $member === '..') {
				continue;
			}
			$abs_member = $dir.$member;
			if (is_file($abs_member)) {
				$dirsize += filesize($abs_member);
			} elseif (is_dir($abs_member)) {
				$dirsize += static::dirsize($abs_member.'/');
			}
		}
		return $dirsize;
	}
1151486
public function setVolumeDriver(string $volumeDriver)
    {
        $this->volumeDriver = $volumeDriver;

        $this->hostConfig = array_merge($this->hostConfig, ['VolumeDriver' => $volumeDriver]);

        return $this;
    }
567254
public function setFolderId($v)
    {
        if ($v !== null) {
            $v = (int) $v;
        }

        if ($this->folder_id !== $v) {
            $this->folder_id = $v;
            $this->modifiedColumns[DealerFolderTableMap::FOLDER_ID] = true;
        }

        if ($this->aFolder !== null && $this->aFolder->getId() !== $v) {
            $this->aFolder = null;
        }


        return $this;
    }
885914
public function runInFolder($folder = null, $tasks = [])
    {
        // Convert to array
        if (!is_array($tasks)) {
            $tasks = [$tasks];
        }

        // Prepend folder
        array_unshift($tasks, 'cd '.$this->paths->getFolder($folder));

        return $this->run($tasks);
    }
655453
public boolean setSoundVolume(int volume) throws CommandExecutionException {
        if (volume < 0) volume = 0;
        if (volume > 100) volume = 100;
        JSONArray payload = new JSONArray();
        payload.put(volume);
        return sendOk("change_sound_volume", payload);
    }
227274
public function getUsedVolume(): int
    {
        $volume = 0;

        /** @var PackedItem $item */
        foreach ($this->items as $item) {
            $volume += $item->getVolume();
        }

        return $volume;
    }
926711
public function folderSize(string $dir):int
    {
        $size = 0;
        foreach (glob(rtrim($dir, '/').'/*', GLOB_NOSORT) as $each) {
            $size += is_file($each) ? filesize($each) : $this->folderSize($each);
        }
        return ($size);
    }
966405
public function setFileFolder(FileFolder $folder)
    {
        $em = \ORM::entityManager('core');

        $this->folderTreeNodeID = $folder->getTreeNodeID();

        $em->persist($this);
        $em->flush();
    }
818919
protected function voteForReadAction($folder, TokenInterface $token)
    {
        return $this->isSubjectInPerimeter($this->getPath($folder), $token->getUser(), MediaFolderInterface::ENTITY_TYPE);
    }
457949
public static double volumeUnionScaled(SpatialComparable box1, SpatialComparable box2, double scale) {
    final int dim = assertSameDimensionality(box1, box2);
    double volume = 1.;
    for(int i = 0; i < dim; i++) {
      final double min = Math.min(box1.getMin(i), box2.getMin(i));
      final double max = Math.max(box1.getMax(i), box2.getMax(i));
      volume *= (max - min) * scale;
    }
    return volume;
  }