Skip to content
This repository has been archived by the owner on Feb 25, 2020. It is now read-only.

Commit

Permalink
Fixed for better exception throwing for issue #117 (#124)
Browse files Browse the repository at this point in the history
$this should not be assigned with any information as long it is not clear that the corresponding repositories can be loaded. Otherwise there won't be throwing the right exception. Now for instance the corrector exception will be

> Error: Your PHP version is not compiled with zip support

Instead of

> Call to a member function close() on string
  • Loading branch information
nextlevelshit authored and Chumper committed Mar 24, 2019
1 parent ff65629 commit 345abf0
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Chumper/Zipper/Zipper.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,28 @@ public function __destruct()
public function make($pathToFile, $type = 'zip')
{
$new = $this->createArchiveFile($pathToFile);
$this->filePath = $pathToFile;

$objectOrName = $type;
if (is_string($type)) {
$objectOrName = 'Chumper\Zipper\Repositories\\'.ucwords($type).'Repository';
$objectOrName = 'Chumper\Zipper\Repositories\\' . ucwords($type) . 'Repository';
}

if (!is_subclass_of($objectOrName, 'Chumper\Zipper\Repositories\RepositoryInterface')) {
throw new \InvalidArgumentException("Class for '{$objectOrName}' must implement RepositoryInterface interface");
}

$this->repository = $type;
if (is_string($objectOrName)) {
$this->repository = new $objectOrName($pathToFile, $new);
try {
if (is_string($objectOrName)) {
$this->repository = new $objectOrName($pathToFile, $new);
} else {
$this->repository = $type;
}
} catch(Exception $e) {
throw $e;
}

$this->filePath = $pathToFile;

return $this;
}

Expand Down

0 comments on commit 345abf0

Please sign in to comment.