Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
Fixes regarding phpdoc and variable-usage (#171)
Browse files Browse the repository at this point in the history
* PelIfd->load(PelDataWindow $d, $offset) will now throw a PelIfdException() instead of running into some undefined status
* PelFormat->getName($type) throws exception instead of returning a string which causes undefined steps in calling sources
* Improced constructor of PelEntryTime
* Updated some static method calls to non-static
* Some casts to "int" have been added
* Fixed "use" statements all over the code
* Fixed several false PhpDoc declarations
* Removed some unused variables
* Updated Readme for tests
  • Loading branch information
weberhofer authored Nov 12, 2020
1 parent 80d5dea commit 6826783
Show file tree
Hide file tree
Showing 62 changed files with 364 additions and 451 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ build-base*
/.phpcs-cache
/.phpunit.result.cache
/composer.lock
/.settings/
13 changes: 7 additions & 6 deletions examples/dirsort.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
*/

/* a printf() variant that appends a newline to the output. */

use lsolesen\pel\Pel;
use lsolesen\pel\PelDataWindow;
use lsolesen\pel\PelJpeg;
use lsolesen\pel\PelTag;
use lsolesen\pel\PelTiff;

function println($args)
{
$args = func_get_args();
Expand All @@ -34,14 +41,8 @@ function println($args)

/* Make PEL speak the users language, if it is available. */
setlocale(LC_ALL, '');
require_once '../autoload.php';

use lsolesen\pel\PelDataWindow;
use lsolesen\pel\PelJpeg;
use lsolesen\pel\PelTiff;

$prog = array_shift($argv);
$error = false;

if (isset($argv[0]) && $argv[0] == '-d') {
Pel::setDebug(true);
Expand Down
3 changes: 1 addition & 2 deletions examples/dump-image.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
/* Make PEL speak the users language, if it is available. */
setlocale(LC_ALL, '');

require_once dirname(__FILE__) . '/../vendor/autoload.php';

use lsolesen\pel\Pel;
use lsolesen\pel\PelConvert;
use lsolesen\pel\PelDataWindow;
use lsolesen\pel\PelJpeg;
use lsolesen\pel\PelTiff;
Expand Down
22 changes: 10 additions & 12 deletions examples/edit-description.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
*/

/* a printf() variant that appends a newline to the output. */
use lsolesen\pel\Pel;
use lsolesen\pel\PelConvert;
use lsolesen\pel\PelDataWindow;
use lsolesen\pel\PelEntryAscii;
use lsolesen\pel\PelExif;
use lsolesen\pel\PelIfd;
use lsolesen\pel\PelJpeg;
use lsolesen\pel\PelTag;
use lsolesen\pel\PelTiff;

function println($args)
{
$args = func_get_args();
Expand All @@ -35,18 +45,6 @@ function println($args)
/* Make PEL speak the users language, if it is available. */
setlocale(LC_ALL, '');

/*
* Load the required files. One would normally just require the
* PelJpeg.php file for dealing with JPEG images, but because this
* example can handle both JPEG and TIFF it loads the PelDataWindow
* class too.
*/
require_once '../autoload.php';

use lsolesen\pel\PelDataWindow;
use lsolesen\pel\PelJpeg;
use lsolesen\pel\PelTiff;

/*
* Store the name of the script in $prog and remove this first part of
* the command line.
Expand Down
41 changes: 23 additions & 18 deletions examples/gps.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@
* used in Exif data.
* - addGpsInfo() adds several Exif tags to your JPEG file.
*/
require_once '../autoload.php';

use lsolesen\pel\PelEntryAscii;
use lsolesen\pel\PelEntryByte;
use lsolesen\pel\PelEntryRational;
use lsolesen\pel\PelEntryUserComment;
use lsolesen\pel\PelExif;
use lsolesen\pel\PelIfd;
use lsolesen\pel\PelJpeg;
use lsolesen\pel\PelTag;
use lsolesen\pel\PelTiff;

/**
Expand Down Expand Up @@ -94,25 +99,25 @@ function convertDecimalToDMS($degree)
* Any old Exif data
* is discarded.
*
* @param
* string the input filename.
* @param
* string the output filename. An updated copy of the input
* @param string $input
* the input filename.
* @param string $output
* the output filename. An updated copy of the input
* image is saved here.
* @param
* string image description.
* @param
* string user comment.
* @param
* string camera model.
* @param
* float longitude expressed as a fractional number of degrees,
* @param string $description
* image description.
* @param string $comment
* user comment.
* @param string $model
* camera model.
* @param float $longitude
* expressed as a fractional number of degrees,
* e.g. 12.345�. Negative values denotes degrees west of Greenwich.
* @param
* float latitude expressed as for longitude. Negative values
* @param float $latitude
* expressed as for longitude. Negative values
* denote degrees south of equator.
* @param
* float the altitude, negative values express an altitude
* @param float $date_time
* the altitude, negative values express an altitude
* below sea level.
* @param
* string the date and time.
Expand Down
12 changes: 6 additions & 6 deletions examples/rename.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
*/

/* a printf() variant that appends a newline to the output. */
use lsolesen\pel\Pel;
use lsolesen\pel\PelDataWindow;
use lsolesen\pel\PelJpeg;
use lsolesen\pel\PelTag;
use lsolesen\pel\PelTiff;

function println($args)
{
$args = func_get_args();
Expand All @@ -44,12 +50,6 @@ function println($args)
/* Make PEL speak the users language, if it is available. */
setlocale(LC_ALL, '');

/* Load the required class definitions. */
require_once '../autoload.php';

use lsolesen\pel\PelDataWindow;
use lsolesen\pel\PelJpeg;
use lsolesen\pel\PelTiff;

$prog = array_shift($argv);
$error = false;
Expand Down
8 changes: 3 additions & 5 deletions examples/resize.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
*/

/* a printf() variant that appends a newline to the output. */
use lsolesen\pel\Pel;
use lsolesen\pel\PelJpeg;

function println($args)
{
$args = func_get_args();
Expand All @@ -35,11 +38,6 @@ function println($args)
/* Make PEL speak the users language, if it is available. */
setlocale(LC_ALL, '');

/* Load the required PEL files for handling JPEG images. */
require_once '../autoload.php';

use lsolesen\pel\PelJpeg;

/*
* Store the name of the script in $prog and remove this first part of
* the command line.
Expand Down
1 change: 0 additions & 1 deletion src/Pel.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
* true or false to {@link Pel::$debug}.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
namespace lsolesen\pel;

Expand Down
5 changes: 4 additions & 1 deletion src/PelCanonMakerNotes.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ public function load()

for ($i = 0; $i < $this->components; $i ++) {
$tag = $this->data->getShort($this->offset + 12 * $i);
$type = $this->data->getShort($this->offset + 12 * $i + 2);
$components = $this->data->getLong($this->offset + 12 * $i + 4);
$data = $this->data->getLong($this->offset + 12 * $i + 8);
// check if tag is defined
Expand All @@ -206,6 +205,7 @@ public function load()
$this->parsePanorama($mkNotesIfd, $this->data, $data, $components);
break;
case PelTag::CANON_PICTURE_INFO:
// TODO: Does not work at the moment
// $this->parsePictureInfo($mkNotesIfd, $this->data, $data, $components);
break;
case PelTag::CANON_FILE_INFO:
Expand Down Expand Up @@ -287,6 +287,9 @@ private function parsePanorama($parent, $data, $offset, $components)
$parent->addSubIfd($panoramaIfd);
}

/**
* This method does not work properly
*/
private function parsePictureInfo($parent, $data, $offset, $components)
{
$type = PelIfd::CANON_PICTURE_INFO;
Expand Down
7 changes: 3 additions & 4 deletions src/PelConvert.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
namespace lsolesen\pel;

/**
* Routines for converting back and forth between bytes and integers.
Expand Down Expand Up @@ -50,8 +51,6 @@
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
namespace lsolesen\pel;

class PelConvert
{

Expand Down Expand Up @@ -143,9 +142,9 @@ public static function longToBytes($value, $endian)
*/
$hex = str_pad(base_convert($value, 10, 16), 8, '0', STR_PAD_LEFT);
if ($endian == self::LITTLE_ENDIAN) {
return (chr(hexdec($hex[6] . $hex[7])) . chr(hexdec($hex[4] . $hex[5])) . chr(hexdec($hex[2] . $hex[3])) . chr(hexdec($hex[0] . $hex[1])));
return chr((int) hexdec($hex[6] . $hex[7])) . chr((int) hexdec($hex[4] . $hex[5])) . chr((int) hexdec($hex[2] . $hex[3])) . chr((int) hexdec($hex[0] . $hex[1]));
} else {
return (chr(hexdec($hex[0] . $hex[1])) . chr(hexdec($hex[2] . $hex[3])) . chr(hexdec($hex[4] . $hex[5])) . chr(hexdec($hex[6] . $hex[7])));
return chr((int) hexdec($hex[0] . $hex[1])) . chr((int) hexdec($hex[2] . $hex[3])) . chr((int) hexdec($hex[4] . $hex[5])) . chr((int) hexdec($hex[6] . $hex[7]));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/PelDataWindow.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PelDataWindow
* PelConvert::LITTLE_ENDIAN} and {@link PelConvert::BIG_ENDIAN}.
*
* @var boolean
* @see PelDataWindow::setByteOrder, PelDataWindow::getByteOrder
* @see PelDataWindow::setByteOrder, getByteOrder
*/
private $order;

Expand Down
3 changes: 1 addition & 2 deletions src/PelDataWindowOffsetException.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
namespace lsolesen\pel;

/**
* An exception thrown when an invalid offset is encountered.
*
* @package PEL
* @subpackage Exception
*/
namespace lsolesen\pel;

class PelDataWindowOffsetException extends PelException
{
}
3 changes: 1 addition & 2 deletions src/PelDataWindowWindowException.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
namespace lsolesen\pel;

/**
* A container for bytes with a limited window of accessible bytes.
Expand All @@ -37,8 +38,6 @@
* @package PEL
* @subpackage Exception
*/
namespace lsolesen\pel;

class PelDataWindowWindowException extends PelException
{
}
16 changes: 8 additions & 8 deletions src/PelEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ public function getIfdType()
/**
* Update the IFD type.
*
* @param
* int must be one of the constants defined in {@link
* @param int $type
* must be one of the constants defined in {@link
* PelIfd}: {@link PelIfd::IFD0} for the main image IFD, {@link
* PelIfd::IFD1} for the thumbnail image IFD, {@link PelIfd::EXIF}
* for the Exif sub-IFD, {@link PelIfd::GPS} for the GPS sub-IFD, or
Expand Down Expand Up @@ -174,8 +174,8 @@ public function getComponents()
/**
* Turn this entry into bytes.
*
* @param
* PelByteOrder the desired byte order, which must be either
* @param boolean $o
* the desired byte order, which must be either
* {@link Convert::LITTLE_ENDIAN} or {@link Convert::BIG_ENDIAN}.
* @return string bytes representing this entry.
*/
Expand All @@ -191,8 +191,8 @@ public function getBytes($o)
* e.g., rationals will be returned as 'x/y', ASCII strings will be
* returned as themselves etc.
*
* @param
* boolean some values can be returned in a long or more
* @param boolean $brief
* some values can be returned in a long or more
* brief form, and this parameter controls that.
* @return string the value as text.
*/
Expand All @@ -214,8 +214,8 @@ abstract public function getValue();
*
* The value should be in the same format as for the constructor.
*
* @param
* mixed the new value.
* @param mixed $value
* the new value.
* @abstract
*
*/
Expand Down
29 changes: 7 additions & 22 deletions src/PelEntryAscii.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,13 @@ public function __construct($tag, $str = '')
{
$this->tag = $tag;
$this->format = PelFormat::ASCII;
self::setValue($str);
$this->setValue($str);
}

/**
* Give the entry a new ASCII value.
*
* This will overwrite the previous value. The value can be
* retrieved later with the {@link getValue} method.
*
* @param
* string the new value of the entry. This should be given
* without any trailing NULL character. The string must be plain
* 7-bit ASCII, the string should contain no high bytes.
* @todo Implement check for high bytes?
* {@inheritdoc}
* @see \lsolesen\pel\PelEntry::setValue()
*/
public function setValue($str)
{
Expand All @@ -111,27 +104,19 @@ public function setValue($str)
}

/**
* Return the ASCII string of the entry.
*
* @return string the string held, without any final NULL character.
* The string will be the same as the one given to {@link setValue}
* or to the {@link __construct constructor}.
* {@inheritdoc}
* @see \lsolesen\pel\PelEntry::getValue()
*/
public function getValue()
{
return $this->str;
}

/**
* Return the ASCII string of the entry.
*
* This methods returns the same as {@link getValue}.
*
* @param
* boolean not used with ASCII entries.
* @return string the string held, without any final NULL character.
* The string will be the same as the one given to {@link setValue}
* or to the {@link __construct constructor}.
* {@inheritdoc}
* @see \lsolesen\pel\PelEntry::getText()
*/
public function getText($brief = false)
{
Expand Down
Loading

0 comments on commit 6826783

Please sign in to comment.