Skip to content

#634 : Adding Strict Types #673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/PhpPresentation/AbstractShape.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

declare(strict_types=1);

namespace PhpOffice\PhpPresentation;

use PhpOffice\PhpPresentation\Shape\Hyperlink;
Expand Down
5 changes: 5 additions & 0 deletions src/PhpPresentation/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

declare(strict_types=1);

namespace PhpOffice\PhpPresentation;

/**
Expand Down Expand Up @@ -43,6 +45,9 @@ public static function autoload(string $class): void
if (0 === strncmp(self::NAMESPACE_PREFIX, $class, $prefixLength)) {
$file = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, $prefixLength));
$file = realpath(__DIR__ . (empty($file) ? '' : DIRECTORY_SEPARATOR) . $file . '.php');
if (!$file) {
return;
}
if (file_exists($file)) {
/** @noinspection PhpIncludeInspection Dynamic includes */
require_once $file;
Expand Down
2 changes: 2 additions & 0 deletions src/PhpPresentation/ComparableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

declare(strict_types=1);

namespace PhpOffice\PhpPresentation;

/**
Expand Down
4 changes: 3 additions & 1 deletion src/PhpPresentation/DocumentLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

declare(strict_types=1);

namespace PhpOffice\PhpPresentation;

use PhpOffice\Common\Drawing;
Expand Down Expand Up @@ -224,7 +226,7 @@ protected function convertUnit(float $value, string $fromUnit, string $toUnit):
$value /= 914400;
break;
case self::UNIT_PIXEL:
$value = Drawing::emuToPixels($value);
$value = Drawing::emuToPixels((int) $value);
break;
case self::UNIT_POINT:
$value /= 12700;
Expand Down
6 changes: 4 additions & 2 deletions src/PhpPresentation/DocumentProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

declare(strict_types=1);

namespace PhpOffice\PhpPresentation;

/**
Expand Down Expand Up @@ -398,9 +400,9 @@ public function isCustomPropertySet(string $propertyName): bool
*
* @param string $propertyName
*
* @return string|null
* @return mixed|null
*/
public function getCustomPropertyValue(string $propertyName): ?string
public function getCustomPropertyValue(string $propertyName)
{
if ($this->isCustomPropertySet($propertyName)) {
return $this->customProperties[$propertyName]['value'];
Expand Down
2 changes: 2 additions & 0 deletions src/PhpPresentation/GeometryCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

declare(strict_types=1);

namespace PhpOffice\PhpPresentation;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/PhpPresentation/HashTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

declare(strict_types=1);

namespace PhpOffice\PhpPresentation;

/**
Expand Down
4 changes: 3 additions & 1 deletion src/PhpPresentation/IOFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

declare(strict_types=1);

namespace PhpOffice\PhpPresentation;

use PhpOffice\PhpPresentation\Reader\ReaderInterface;
Expand Down Expand Up @@ -51,7 +53,7 @@ public static function createWriter(PhpPresentation $phpPresentation, string $na
*
* @throws \Exception
*/
public static function createReader(string $name = ''): ReaderInterface
public static function createReader(string $name): ReaderInterface
{
$class = 'PhpOffice\\PhpPresentation\\Reader\\' . $name;

Expand Down
2 changes: 2 additions & 0 deletions src/PhpPresentation/PhpPresentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

declare(strict_types=1);

namespace PhpOffice\PhpPresentation;

use ArrayObject;
Expand Down
2 changes: 2 additions & 0 deletions src/PhpPresentation/PresentationProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

declare(strict_types=1);

namespace PhpOffice\PhpPresentation;

class PresentationProperties
Expand Down
2 changes: 2 additions & 0 deletions src/PhpPresentation/Reader/ODPresentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

declare(strict_types=1);

namespace PhpOffice\PhpPresentation\Reader;

use DateTime;
Expand Down
61 changes: 32 additions & 29 deletions src/PhpPresentation/Reader/PowerPoint2007.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

declare(strict_types=1);

namespace PhpOffice\PhpPresentation\Reader;

use DateTime;
Expand Down Expand Up @@ -540,24 +542,25 @@ protected function loadMasterSlide(string $sPart, string $baseFile): void
} else {
$level = str_replace('a:lvl', '', $oElementLvl->nodeName);
$level = str_replace('pPr', '', $level);
$level = intval($level);
}

if ($oElementLvl->hasAttribute('algn')) {
$oRTParagraph->getAlignment()->setHorizontal($oElementLvl->getAttribute('algn'));
}
if ($oElementLvl->hasAttribute('marL')) {
$val = $oElementLvl->getAttribute('marL');
$val = CommonDrawing::emuToPixels($val);
$val = (int) $oElementLvl->getAttribute('marL');
$val = CommonDrawing::emuToPixels((int) $val);
$oRTParagraph->getAlignment()->setMarginLeft($val);
}
if ($oElementLvl->hasAttribute('marR')) {
$val = $oElementLvl->getAttribute('marR');
$val = CommonDrawing::emuToPixels($val);
$val = (int) $oElementLvl->getAttribute('marR');
$val = CommonDrawing::emuToPixels((int) $val);
$oRTParagraph->getAlignment()->setMarginRight($val);
}
if ($oElementLvl->hasAttribute('indent')) {
$val = $oElementLvl->getAttribute('indent');
$val = CommonDrawing::emuToPixels($val);
$val = (int) $oElementLvl->getAttribute('indent');
$val = CommonDrawing::emuToPixels((int) $val);
$oRTParagraph->getAlignment()->setIndent($val);
}
$oElementLvlDefRPR = $xmlReader->getElement('a:defRPr', $oElementLvl);
Expand Down Expand Up @@ -840,27 +843,27 @@ protected function loadShapeDrawing(XMLReader $document, DOMElement $node, Abstr
$oElement = $document->getElement('p:spPr/a:xfrm', $node);
if ($oElement instanceof DOMElement) {
if ($oElement->hasAttribute('rot')) {
$oShape->setRotation((int) CommonDrawing::angleToDegrees($oElement->getAttribute('rot')));
$oShape->setRotation((int) CommonDrawing::angleToDegrees((int) $oElement->getAttribute('rot')));
}
}

$oElement = $document->getElement('p:spPr/a:xfrm/a:off', $node);
if ($oElement instanceof DOMElement) {
if ($oElement->hasAttribute('x')) {
$oShape->setOffsetX(CommonDrawing::emuToPixels($oElement->getAttribute('x')));
$oShape->setOffsetX(CommonDrawing::emuToPixels((int) $oElement->getAttribute('x')));
}
if ($oElement->hasAttribute('y')) {
$oShape->setOffsetY(CommonDrawing::emuToPixels($oElement->getAttribute('y')));
$oShape->setOffsetY(CommonDrawing::emuToPixels((int) $oElement->getAttribute('y')));
}
}

$oElement = $document->getElement('p:spPr/a:xfrm/a:ext', $node);
if ($oElement instanceof DOMElement) {
if ($oElement->hasAttribute('cx')) {
$oShape->setWidth(CommonDrawing::emuToPixels($oElement->getAttribute('cx')));
$oShape->setWidth(CommonDrawing::emuToPixels((int) $oElement->getAttribute('cx')));
}
if ($oElement->hasAttribute('cy')) {
$oShape->setHeight(CommonDrawing::emuToPixels($oElement->getAttribute('cy')));
$oShape->setHeight(CommonDrawing::emuToPixels((int) $oElement->getAttribute('cy')));
}
}

Expand All @@ -871,13 +874,13 @@ protected function loadShapeDrawing(XMLReader $document, DOMElement $node, Abstr
$oSubElement = $document->getElement('a:outerShdw', $oElement);
if ($oSubElement instanceof DOMElement) {
if ($oSubElement->hasAttribute('blurRad')) {
$oShape->getShadow()->setBlurRadius(CommonDrawing::emuToPixels($oSubElement->getAttribute('blurRad')));
$oShape->getShadow()->setBlurRadius(CommonDrawing::emuToPixels((int) $oSubElement->getAttribute('blurRad')));
}
if ($oSubElement->hasAttribute('dist')) {
$oShape->getShadow()->setDistance(CommonDrawing::emuToPixels($oSubElement->getAttribute('dist')));
$oShape->getShadow()->setDistance(CommonDrawing::emuToPixels((int) $oSubElement->getAttribute('dist')));
}
if ($oSubElement->hasAttribute('dir')) {
$oShape->getShadow()->setDirection((int) CommonDrawing::angleToDegrees($oSubElement->getAttribute('dir')));
$oShape->getShadow()->setDirection((int) CommonDrawing::angleToDegrees((int) $oSubElement->getAttribute('dir')));
}
if ($oSubElement->hasAttribute('algn')) {
$oShape->getShadow()->setAlignment($oSubElement->getAttribute('algn'));
Expand Down Expand Up @@ -922,26 +925,26 @@ protected function loadShapeRichText(XMLReader $document, DOMElement $node, Abst

$oElement = $document->getElement('p:spPr/a:xfrm', $node);
if ($oElement instanceof DOMElement && $oElement->hasAttribute('rot')) {
$oShape->setRotation((int) CommonDrawing::angleToDegrees($oElement->getAttribute('rot')));
$oShape->setRotation((int) CommonDrawing::angleToDegrees((int) $oElement->getAttribute('rot')));
}

$oElement = $document->getElement('p:spPr/a:xfrm/a:off', $node);
if ($oElement instanceof DOMElement) {
if ($oElement->hasAttribute('x')) {
$oShape->setOffsetX(CommonDrawing::emuToPixels($oElement->getAttribute('x')));
$oShape->setOffsetX(CommonDrawing::emuToPixels((int) $oElement->getAttribute('x')));
}
if ($oElement->hasAttribute('y')) {
$oShape->setOffsetY(CommonDrawing::emuToPixels($oElement->getAttribute('y')));
$oShape->setOffsetY(CommonDrawing::emuToPixels((int) $oElement->getAttribute('y')));
}
}

$oElement = $document->getElement('p:spPr/a:xfrm/a:ext', $node);
if ($oElement instanceof DOMElement) {
if ($oElement->hasAttribute('cx')) {
$oShape->setWidth(CommonDrawing::emuToPixels($oElement->getAttribute('cx')));
$oShape->setWidth(CommonDrawing::emuToPixels((int) $oElement->getAttribute('cx')));
}
if ($oElement->hasAttribute('cy')) {
$oShape->setHeight(CommonDrawing::emuToPixels($oElement->getAttribute('cy')));
$oShape->setHeight(CommonDrawing::emuToPixels((int) $oElement->getAttribute('cy')));
}
}

Expand Down Expand Up @@ -987,20 +990,20 @@ protected function loadShapeTable(XMLReader $document, DOMElement $node, Abstrac
$oElement = $document->getElement('p:xfrm/a:off', $node);
if ($oElement instanceof DOMElement) {
if ($oElement->hasAttribute('x')) {
$oShape->setOffsetX(CommonDrawing::emuToPixels($oElement->getAttribute('x')));
$oShape->setOffsetX(CommonDrawing::emuToPixels((int) $oElement->getAttribute('x')));
}
if ($oElement->hasAttribute('y')) {
$oShape->setOffsetY(CommonDrawing::emuToPixels($oElement->getAttribute('y')));
$oShape->setOffsetY(CommonDrawing::emuToPixels((int) $oElement->getAttribute('y')));
}
}

$oElement = $document->getElement('p:xfrm/a:ext', $node);
if ($oElement instanceof DOMElement) {
if ($oElement->hasAttribute('cx')) {
$oShape->setWidth(CommonDrawing::emuToPixels($oElement->getAttribute('cx')));
$oShape->setWidth(CommonDrawing::emuToPixels((int) $oElement->getAttribute('cx')));
}
if ($oElement->hasAttribute('cy')) {
$oShape->setHeight(CommonDrawing::emuToPixels($oElement->getAttribute('cy')));
$oShape->setHeight(CommonDrawing::emuToPixels((int) $oElement->getAttribute('cy')));
}
}

Expand All @@ -1009,7 +1012,7 @@ protected function loadShapeTable(XMLReader $document, DOMElement $node, Abstrac
$oShape->createRow();
foreach ($arrayElements as $key => $oElement) {
if ($oElement instanceof DOMElement && $oElement->getAttribute('w')) {
$oShape->getRow(0)->getCell($key)->setWidth(CommonDrawing::emuToPixels($oElement->getAttribute('w')));
$oShape->getRow(0)->getCell($key)->setWidth(CommonDrawing::emuToPixels((int) $oElement->getAttribute('w')));
}
}

Expand All @@ -1023,7 +1026,7 @@ protected function loadShapeTable(XMLReader $document, DOMElement $node, Abstrac
$oRow = $oShape->createRow();
}
if ($oElementRow->hasAttribute('h')) {
$oRow->setHeight(CommonDrawing::emuToPixels($oElementRow->getAttribute('h')));
$oRow->setHeight(CommonDrawing::emuToPixels((int) $oElementRow->getAttribute('h')));
}
$arrayElementsCell = $document->getElements('a:tc', $oElementRow);
foreach ($arrayElementsCell as $keyCell => $oElementCell) {
Expand Down Expand Up @@ -1125,13 +1128,13 @@ protected function loadParagraph(XMLReader $document, DOMElement $oElement, $oSh
$oParagraph->getAlignment()->setVertical($oSubElement->getAttribute('fontAlgn'));
}
if ($oSubElement->hasAttribute('marL')) {
$oParagraph->getAlignment()->setMarginLeft(CommonDrawing::emuToPixels($oSubElement->getAttribute('marL')));
$oParagraph->getAlignment()->setMarginLeft(CommonDrawing::emuToPixels((int) $oSubElement->getAttribute('marL')));
}
if ($oSubElement->hasAttribute('marR')) {
$oParagraph->getAlignment()->setMarginRight(CommonDrawing::emuToPixels($oSubElement->getAttribute('marR')));
$oParagraph->getAlignment()->setMarginRight(CommonDrawing::emuToPixels((int) $oSubElement->getAttribute('marR')));
}
if ($oSubElement->hasAttribute('indent')) {
$oParagraph->getAlignment()->setIndent(CommonDrawing::emuToPixels($oSubElement->getAttribute('indent')));
$oParagraph->getAlignment()->setIndent(CommonDrawing::emuToPixels((int) $oSubElement->getAttribute('indent')));
}
if ($oSubElement->hasAttribute('lvl')) {
$oParagraph->getAlignment()->setLevel((int) $oSubElement->getAttribute('lvl'));
Expand Down Expand Up @@ -1339,7 +1342,7 @@ protected function loadStyleFill(XMLReader $xmlReader, DOMElement $oElement): ?F

$oRotation = $xmlReader->getElement('a:lin', $oElementFill);
if ($oRotation instanceof DOMElement && $oRotation->hasAttribute('ang')) {
$oFill->setRotation(CommonDrawing::angleToDegrees($oRotation->getAttribute('ang')));
$oFill->setRotation(CommonDrawing::angleToDegrees((int) $oRotation->getAttribute('ang')));
}

return $oFill;
Expand Down
Loading