Example #1
0
 /**
  * @param UploadedFile $file
  * @param $user
  * @param $oldSize
  * @param $newSize
  * @param $path
  * @return CompressedFileResponse
  */
 private function handleNewFileBigger(UploadedFile $file, $user, $path, $oldSize, $newSize)
 {
     $savingCalculator = new SavingCalculator();
     $saving = $savingCalculator->calculate($oldSize, $newSize);
     $fomatter = new FileSizeFormatter();
     $this->logger->info(sprintf('[%s] New image is bigger than the original one - returning original image (%s) - Old: %s, New: %s, Saving: %d%%', $user['name'], $file->getClientOriginalName(), $fomatter->humanReadable($oldSize), $fomatter->humanReadable($newSize), $saving));
     $binaryContent = $this->fileHandler->getFileContent($file->getRealPath());
     $this->fileHandler->delete($path);
     $newSize = $oldSize;
     $saving = 0;
     return new CompressedFileResponse($oldSize, $newSize, $saving, $binaryContent);
 }
 public function testHumanReadableWithBytesSmallerZero()
 {
     $fomatter = new FileSizeFormatter();
     $this->setExpectedException('InvalidArgumentException');
     $fomatter->humanReadable(-1);
 }