Skip to content

Commit

Permalink
Fixed for better exception throwing for issue Chumper#117
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 May 5, 2018
1 parent fe07466 commit cc5c4a0
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 cc5c4a0

Please sign in to comment.