Skip to content

Commit

Permalink
PHPOffice#634 : Set specific exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Sep 7, 2021
1 parent a964f3b commit cea5f34
Show file tree
Hide file tree
Showing 103 changed files with 1,220 additions and 1,094 deletions.
15 changes: 5 additions & 10 deletions src/PhpPresentation/AbstractShape.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

namespace PhpOffice\PhpPresentation;

use PhpOffice\PhpPresentation\Exception\ShapeContainerAlreadyAssignedException;
use PhpOffice\PhpPresentation\Shape\Hyperlink;
use PhpOffice\PhpPresentation\Shape\Placeholder;
use PhpOffice\PhpPresentation\Style\Border;
Expand Down Expand Up @@ -146,7 +147,7 @@ public function getContainer(): ?ShapeContainerInterface
* @param ShapeContainerInterface $pValue
* @param bool $pOverrideOld If a Slide has already been assigned, overwrite it and remove image from old Slide?
*
* @throws \Exception
* @throws ShapeContainerAlreadyAssignedException
*
* @return $this
*/
Expand Down Expand Up @@ -175,7 +176,7 @@ public function setContainer(ShapeContainerInterface $pValue = null, $pOverrideO
// Set new \PhpOffice\PhpPresentation\Slide
$this->setContainer($pValue);
} else {
throw new \Exception(sprintf('A %s has already been assigned. Shapes can only exist on one %s.', ShapeContainerInterface::class, ShapeContainerInterface::class));
throw new ShapeContainerAlreadyAssignedException(self::class);
}
}

Expand Down Expand Up @@ -328,8 +329,6 @@ public function getShadow(): ?Shadow
}

/**
* @throws \Exception
*
* @return $this
*/
public function setShadow(Shadow $pValue = null)
Expand All @@ -350,9 +349,7 @@ public function hasHyperlink()
}

/**
* Get Hyperlink.
*
* @throws \Exception
* Get Hyperlink
*/
public function getHyperlink(): Hyperlink
{
Expand All @@ -364,9 +361,7 @@ public function getHyperlink(): Hyperlink
}

/**
* Set Hyperlink.
*
* @throws \Exception
* Set Hyperlink
*/
public function setHyperlink(Hyperlink $pHyperlink = null): self
{
Expand Down
32 changes: 32 additions & 0 deletions src/PhpPresentation/Exception/DirectoryNotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* This file is part of PHPPresentation - A pure PHP library for reading and writing
* presentations documents.
*
* PHPPresentation is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
*
* @see https://github.com/PHPOffice/PHPPresentation
*
* @copyright 2009-2015 PHPPresentation contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

declare(strict_types=1);

namespace PhpOffice\PhpPresentation\Exception;

class DirectoryNotFoundException extends PhpPresentationException
{
public function __construct(string $path)
{
parent::__construct(sprintf(
'The directory %s doesn\'t exist',
$path
));
}
}
29 changes: 29 additions & 0 deletions src/PhpPresentation/Exception/FeatureNotImplementedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* This file is part of PHPPresentation - A pure PHP library for reading and writing
* presentations documents.
*
* PHPPresentation is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
*
* @see https://github.com/PHPOffice/PHPPresentation
*
* @copyright 2009-2015 PHPPresentation contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

declare(strict_types=1);

namespace PhpOffice\PhpPresentation\Exception;

class FeatureNotImplementedException extends PhpPresentationException
{
public function __construct()
{
parent::__construct('The feature is not implemented. Please create an issue.');
}
}
33 changes: 33 additions & 0 deletions src/PhpPresentation/Exception/FileCopyException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* This file is part of PHPPresentation - A pure PHP library for reading and writing
* presentations documents.
*
* PHPPresentation is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
*
* @see https://github.com/PHPOffice/PHPPresentation
*
* @copyright 2009-2015 PHPPresentation contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

declare(strict_types=1);

namespace PhpOffice\PhpPresentation\Exception;

class FileCopyException extends PhpPresentationException
{
public function __construct(string $source, string $destination)
{
parent::__construct(sprintf(
'The file %s can\'t be copied to %s',
$source,
$destination
));
}
}
32 changes: 32 additions & 0 deletions src/PhpPresentation/Exception/FileNotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* This file is part of PHPPresentation - A pure PHP library for reading and writing
* presentations documents.
*
* PHPPresentation is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
*
* @see https://github.com/PHPOffice/PHPPresentation
*
* @copyright 2009-2015 PHPPresentation contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

declare(strict_types=1);

namespace PhpOffice\PhpPresentation\Exception;

class FileNotFoundException extends PhpPresentationException
{
public function __construct(string $path)
{
parent::__construct(sprintf(
'The file "%s" doesn\'t exist',
$path
));
}
}
32 changes: 32 additions & 0 deletions src/PhpPresentation/Exception/FileRemoveException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* This file is part of PHPPresentation - A pure PHP library for reading and writing
* presentations documents.
*
* PHPPresentation is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
*
* @see https://github.com/PHPOffice/PHPPresentation
*
* @copyright 2009-2015 PHPPresentation contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

declare(strict_types=1);

namespace PhpOffice\PhpPresentation\Exception;

class FileRemoveException extends PhpPresentationException
{
public function __construct(string $path)
{
parent::__construct(sprintf(
'The file %s can\'t be removed',
$path
));
}
}
33 changes: 33 additions & 0 deletions src/PhpPresentation/Exception/InvalidClassException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* This file is part of PHPPresentation - A pure PHP library for reading and writing
* presentations documents.
*
* PHPPresentation is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
*
* @see https://github.com/PHPOffice/PHPPresentation
*
* @copyright 2009-2015 PHPPresentation contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

declare(strict_types=1);

namespace PhpOffice\PhpPresentation\Exception;

class InvalidClassException extends PhpPresentationException
{
public function __construct(string $class, string $error)
{
parent::__construct(sprintf(
'The class %s is invalid (%s)',
$class,
$error
));
}
}
42 changes: 42 additions & 0 deletions src/PhpPresentation/Exception/InvalidFileFormatException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* This file is part of PHPPresentation - A pure PHP library for reading and writing
* presentations documents.
*
* PHPPresentation is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
*
* @see https://github.com/PHPOffice/PHPPresentation
*
* @copyright 2009-2015 PHPPresentation contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

declare(strict_types=1);

namespace PhpOffice\PhpPresentation\Exception;

class InvalidFileFormatException extends PhpPresentationException
{
public function __construct(string $path, string $class, string $error = '')
{
if ($class) {
$class = 'class ' . $class;
}
if ($error) {
$error = '(' . $error . ')';
}

parent::__construct(sprintf(
'The file %s is not in the format supported by %s%s%s',
$path,
$class,
!empty($error) ? ' ' : '',
$error
));
}
}
33 changes: 33 additions & 0 deletions src/PhpPresentation/Exception/InvalidParameterException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* This file is part of PHPPresentation - A pure PHP library for reading and writing
* presentations documents.
*
* PHPPresentation is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
*
* @see https://github.com/PHPOffice/PHPPresentation
*
* @copyright 2009-2015 PHPPresentation contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

declare(strict_types=1);

namespace PhpOffice\PhpPresentation\Exception;

class InvalidParameterException extends PhpPresentationException
{
public function __construct(string $parameter, string $value)
{
parent::__construct(sprintf(
'The parameter %s can\'t have the value "%s"',
$parameter,
$value
));
}
}
34 changes: 34 additions & 0 deletions src/PhpPresentation/Exception/OutOfBoundsException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* This file is part of PHPPresentation - A pure PHP library for reading and writing
* presentations documents.
*
* PHPPresentation is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
*
* @see https://github.com/PHPOffice/PHPPresentation
*
* @copyright 2009-2015 PHPPresentation contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

declare(strict_types=1);

namespace PhpOffice\PhpPresentation\Exception;

class OutOfBoundsException extends PhpPresentationException
{
public function __construct(int $minBounds, ?int $maxBounds, int $expectedBounds)
{
parent::__construct(sprintf(
'The expected value (%d) is out of bounds (%d, %s)',
$expectedBounds,
$minBounds,
$maxBounds ?? 'Infinite'
));
}
}
27 changes: 27 additions & 0 deletions src/PhpPresentation/Exception/PhpPresentationException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* This file is part of PHPPresentation - A pure PHP library for reading and writing
* presentations documents.
*
* PHPPresentation is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
*
* @see https://github.com/PHPOffice/PHPPresentation
*
* @copyright 2009-2015 PHPPresentation contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

declare(strict_types=1);

namespace PhpOffice\PhpPresentation\Exception;

use Exception;

class PhpPresentationException extends Exception
{
}
Loading

0 comments on commit cea5f34

Please sign in to comment.