From a4b44b41451e99e6210c7bc67371e7c8ca983669 Mon Sep 17 00:00:00 2001 From: Rasmus Lerdorf Date: Wed, 9 Sep 2015 08:30:30 -0700 Subject: [PATCH] phpdoc type hint cleanup --- WavFile.php | 33 +++++++++++++++++++++++---------- securimage.php | 50 ++++++++++++++++++++++++++------------------------ 2 files changed, 49 insertions(+), 34 deletions(-) diff --git a/WavFile.php b/WavFile.php index e9b6888..8702d22 100644 --- a/WavFile.php +++ b/WavFile.php @@ -169,7 +169,7 @@ class WavFile /** @var int Size of the data chunk in the opened wav file */ protected $_dataSize_fp; - /** @var int Does _dataSize really reflect strlen($_samples)? Case when a wav file is read with readData = false */ + /** @var bool Does _dataSize really reflect strlen($_samples)? Case when a wav file is read with readData = false */ protected $_dataSize_valid; /** @var int Starting offset of data chunk */ @@ -178,7 +178,7 @@ class WavFile /** @var int The audio format - WavFile::WAVE_FORMAT_* */ protected $_audioFormat; - /** @var int The audio subformat - WavFile::WAVE_SUBFORMAT_* */ + /** @var int|string|null The audio subformat - WavFile::WAVE_SUBFORMAT_* */ protected $_audioSubFormat; /** @var int Number of channels in the audio file */ @@ -211,7 +211,7 @@ class WavFile /** @var string Binary string of samples */ protected $_samples; - /** @var resource The file pointer used for reading wavs from file or memory */ + /** @var resource|null The file pointer used for reading wavs from file or memory */ protected $_fp; @@ -296,7 +296,7 @@ public function __toString() * * @param string $sampleBinary (Required) The sample to decode. * @param int $bitDepth (Optional) The bits per sample to decode. If omitted, derives it from the length of $sampleBinary. - * @return int|float The numeric sample value. Float for 32-bit samples. Returns null for unsupported bit depths. + * @return int|float|null The numeric sample value. Float for 32-bit samples. Returns null for unsupported bit depths. */ public static function unpackSample($sampleBinary, $bitDepth = null) { @@ -342,7 +342,7 @@ public static function unpackSample($sampleBinary, $bitDepth = null) * * @param int|float $sample (Required) The sample to encode. Has to be within valid range for $bitDepth. Float values only for 32 bits. * @param int $bitDepth (Required) The bits per sample to encode with. - * @return string The encoded binary sample. Returns null for unsupported bit depths. + * @return string|null The encoded binary sample. Returns null for unsupported bit depths. */ public static function packSample($sample, $bitDepth) { @@ -469,6 +469,7 @@ public function getActualSize() { return $this->_actualSize; } + /** @param int $actualSize */ protected function setActualSize($actualSize = null) { if (is_null($actualSize)) { $this->_actualSize = 8 + $this->_chunkSize; // + "RIFF" header (ID + size) @@ -483,6 +484,7 @@ public function getChunkSize() { return $this->_chunkSize; } + /** @param int $chunkSize */ protected function setChunkSize($chunkSize = null) { if (is_null($chunkSize)) { $this->_chunkSize = 4 + // "WAVE" chunk @@ -503,6 +505,7 @@ public function getFmtChunkSize() { return $this->_fmtChunkSize; } + /** @param int $fmtChunkSize */ protected function setFmtChunkSize($fmtChunkSize = null) { if (is_null($fmtChunkSize)) { $this->_fmtChunkSize = 16 + $this->_fmtExtendedSize; @@ -520,6 +523,7 @@ public function getFmtExtendedSize() { return $this->_fmtExtendedSize; } + /** @param int $fmtExtendedSize */ protected function setFmtExtendedSize($fmtExtendedSize = null) { if (is_null($fmtExtendedSize)) { if ($this->_audioFormat == self::WAVE_FORMAT_EXTENSIBLE) { @@ -542,6 +546,7 @@ public function getFactChunkSize() { return $this->_factChunkSize; } + /** @param int $factChunkSize */ protected function setFactChunkSize($factChunkSize = null) { if (is_null($factChunkSize)) { if ($this->_audioFormat != self::WAVE_FORMAT_PCM) { @@ -563,6 +568,7 @@ public function getDataSize() { return $this->_dataSize; } + /** @param int $dataSize */ protected function setDataSize($dataSize = null) { if (is_null($dataSize)) { $this->_dataSize = strlen($this->_samples); @@ -581,6 +587,7 @@ public function getDataOffset() { return $this->_dataOffset; } + /** @param int $dataOffset */ protected function setDataOffset($dataOffset = null) { if (is_null($dataOffset)) { $this->_dataOffset = 8 + // "RIFF" header (ID + size) @@ -599,6 +606,7 @@ public function getAudioFormat() { return $this->_audioFormat; } + /** @param int $audioFormat */ protected function setAudioFormat($audioFormat = null) { if (is_null($audioFormat)) { if (($this->_bitsPerSample <= 16 || $this->_bitsPerSample == 32) @@ -628,6 +636,7 @@ public function getAudioSubFormat() { return $this->_audioSubFormat; } + /** @param int $audioSubFormat */ protected function setAudioSubFormat($audioSubFormat = null) { if (is_null($audioSubFormat)) { if ($this->_bitsPerSample == 32) { @@ -646,6 +655,7 @@ public function getNumChannels() { return $this->_numChannels; } + /** @param int $numChannels */ public function setNumChannels($numChannels) { if ($numChannels < 1 || $numChannels > self::MAX_CHANNEL) { throw new WavFileException('Unsupported number of channels. Only up to ' . self::MAX_CHANNEL . ' channels are supported.'); @@ -748,6 +758,7 @@ public function getBlockAlign() { return $this->_blockAlign; } + /** @param int $blockAlign */ protected function setBlockAlign($blockAlign = null) { if (is_null($blockAlign)) { $this->_blockAlign = $this->_numChannels * $this->_bitsPerSample / 8; @@ -765,6 +776,7 @@ public function getNumBlocks() return $this->_numBlocks; } + /** @param int $numBlocks */ protected function setNumBlocks($numBlocks = null) { if (is_null($numBlocks)) { $this->_numBlocks = (int)($this->_dataSize / $this->_blockAlign); // do not count incomplete sample blocks @@ -779,6 +791,7 @@ public function getByteRate() { return $this->_byteRate; } + /** @param int $byteRate */ protected function setByteRate($byteRate = null) { if (is_null($byteRate)) { $this->_byteRate = $this->_sampleRate * $this->_numChannels * $this->_bitsPerSample / 8; @@ -1016,7 +1029,7 @@ public function setWavData(&$data, $free = true) /** * Read wav file from a stream. * - * @param $readData (Optional) If true, also read the data chunk. + * @param bool $readData (Optional) If true, also read the data chunk. * @throws WavFormatException * @throws WavFileException */ @@ -1292,8 +1305,8 @@ protected function readWavHeader() /** * Read the wav data from the file into the buffer. * - * @param $dataOffset (Optional) The byte offset to skip before starting to read. Must be a multiple of BlockAlign. - * @param $dataSize (Optional) The size of the data to read in bytes. Must be a multiple of BlockAlign. Defaults to all data. + * @param int $dataOffset (Optional) The byte offset to skip before starting to read. Must be a multiple of BlockAlign. + * @param int $dataSize (Optional) The size of the data to read in bytes. Must be a multiple of BlockAlign. Defaults to all data. * @throws WavFileException */ public function readWavData($dataOffset = 0, $dataSize = null) @@ -1335,7 +1348,7 @@ public function readWavData($dataOffset = 0, $dataSize = null) * Return a single sample block from the file. * * @param int $blockNum (Required) The sample block number. Zero based. - * @return string The binary sample block (all channels). Returns null if the sample block number was out of range. + * @return string|null The binary sample block (all channels). Returns null if the sample block number was out of range. */ public function getSampleBlock($blockNum) { @@ -1404,7 +1417,7 @@ public function setSampleBlock($sampleBlock, $blockNum) * * @param int $blockNum (Required) The sample block number to fetch. Zero based. * @param int $channelNum (Required) The channel number within the sample block to fetch. First channel is 1. - * @return float The float sample value. Returns null if the sample block number was out of range. + * @return float|null The float sample value. Returns null if the sample block number was out of range. * @throws WavFileException */ public function getSampleValue($blockNum, $channelNum) diff --git a/securimage.php b/securimage.php index aa6727e..3955518 100644 --- a/securimage.php +++ b/securimage.php @@ -300,25 +300,25 @@ class Securimage /** * The background color of the captcha - * @var Securimage_Color + * @var Securimage_Color|string */ public $image_bg_color = '#ffffff'; /** * The color of the captcha text - * @var Securimage_Color + * @var Securimage_Color|string */ public $text_color = '#707070'; /** * The color of the lines over the captcha - * @var Securimage_Color + * @var Securimage_Color|string */ public $line_color = '#707070'; /** * The color of the noise that is drawn - * @var Securimage_Color + * @var Securimage_Color|string */ public $noise_color = '#707070'; @@ -415,7 +415,7 @@ class Securimage /** * The color of the signature text - * @var Securimage_Color + * @var Securimage_Color|string */ public $signature_color = '#707070'; @@ -743,7 +743,7 @@ class Securimage /** * The background image GD resource - * @var resource + * @var string */ protected $bgimg; @@ -769,7 +769,7 @@ class Securimage * Either the case-sensitive/insensitive word captcha, or the solution to * the math captcha. * - * @var string Captcha challenge value + * @var string|bool Captcha challenge value */ protected $code; @@ -844,35 +844,35 @@ class Securimage /** * PDO connection when a database is used * - * @var resource + * @var PDO|bool */ protected $pdo_conn; /** - * The GD color resource for the background color + * The GD color for the background color * - * @var resource + * @var int */ protected $gdbgcolor; /** - * The GD color resource for the text color + * The GD color for the text color * - * @var resource + * @var int */ protected $gdtextcolor; /** - * The GD color resource for the line color + * The GD color for the line color * - * @var resource + * @var int */ protected $gdlinecolor; /** - * The GD color resource for the signature text color + * The GD color for the signature text color * - * @var resource + * @var int */ protected $gdsignaturecolor; @@ -1310,6 +1310,7 @@ public function setNamespace($namespace) * $img->outputAudioFile(); // outputs a wav file to the browser * exit; * + * @param string $format */ public function outputAudioFile($format = null) { @@ -1596,6 +1597,7 @@ protected function setBackground() /** * Scan the directory for a background image to use + * @return string|bool */ protected function getBackgroundFromDirectory() { @@ -1641,7 +1643,7 @@ public function createCode() } } while ($c <= 0); // no negative #'s or 0 - $this->code = $c; + $this->code = "$c"; $this->code_display = "$left $sign $right"; break; } @@ -1694,7 +1696,7 @@ protected function drawWord() $x = floor($width2 / 2 - $tx / 2 - $bb[0]); $y = round($height2 / 2 - $ty / 2 - $bb[1]); - imagettftext($this->tmpimg, $font_size, 0, $x, $y, $this->gdtextcolor, $this->ttf_file, $this->code_display); + imagettftext($this->tmpimg, $font_size, 0, (int)$x, (int)$y, $this->gdtextcolor, $this->ttf_file, $this->code_display); } else { $font_size = $this->image_height * $ratio; $bb = imageftbbox($font_size, 0, $this->ttf_file, $this->code_display); @@ -1703,7 +1705,7 @@ protected function drawWord() $x = floor($this->image_width / 2 - $tx / 2 - $bb[0]); $y = round($this->image_height / 2 - $ty / 2 - $bb[1]); - imagettftext($this->im, $font_size, 0, $x, $y, $this->gdtextcolor, $this->ttf_file, $this->code_display); + imagettftext($this->im, $font_size, 0, (int)$x, (int)$y, $this->gdtextcolor, $this->ttf_file, $this->code_display); } } @@ -1955,7 +1957,7 @@ protected function getAudibleCode() * Seek to a random offset in the file and reads a block of data and returns a line from the file. * * @param int $numWords Number of words (lines) to read from the file - * @return string|array Returns a string if only one word is to be read, or an array of words + * @return string|array|bool Returns a string if only one word is to be read, or an array of words */ protected function readCodeFromFile($numWords = 1) { @@ -2207,7 +2209,7 @@ protected function openDatabase() } } catch (Exception $ex) { trigger_error($ex->getMessage(), E_USER_WARNING); - $this->pdo_conn = null; + $this->pdo_conn = false; return false; } @@ -2453,8 +2455,8 @@ protected function purgeOldCodesFromDatabase() $query = sprintf("DELETE FROM %s WHERE %s - created > %s", $this->database_table, - $this->pdo_conn->quote($now, PDO::PARAM_INT), - $this->pdo_conn->quote($limit, PDO::PARAM_INT)); + $now, + $this->pdo_conn->quote("$limit", PDO::PARAM_INT)); $result = $this->pdo_conn->query($query); } @@ -2886,7 +2888,7 @@ function frand() /** * Convert an html color code to a Securimage_Color * @param string $color - * @param Securimage_Color $default The defalt color to use if $color is invalid + * @param Securimage_Color|string $default The defalt color to use if $color is invalid */ protected function initColor($color, $default) {