diff --git a/.gitattributes b/.gitattributes index 0545406..5a28b48 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,3 +5,4 @@ tools/ export-ignore .gitignore export-ignore package.php export-ignore package.xml export-ignore +phpstan.neon export-ignore \ No newline at end of file diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index bcce56c..f03d8b8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,6 +35,7 @@ jobs: run: | composer require --dev 'phpunit/phpunit:^4.8.36 || ^5.7.21 || ^6 || ^7' --no-update sed -i 's/: void//g' tests/*.php + composer remove phpstan/phpstan --no-update - name: Install dependencies run: composer install --prefer-dist --no-interaction --no-progress diff --git a/.gitignore b/.gitignore index caeb939..c0f18a7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ vendor tests/config.php tests/debug.log tests/test-keychain/ +tests/.phpunit.result.cache diff --git a/Crypt/GPG.php b/Crypt/GPG.php index 07a44c1..8870ad9 100644 --- a/Crypt/GPG.php +++ b/Crypt/GPG.php @@ -330,7 +330,7 @@ public function importKeyFile($filename) * the private key. For example, * "Test User (example) ", * "test@example.com" or a hexadecimal string. - * @param boolean $armor optional. If true, ASCII armored data is returned; + * @param bool $armor optional. If true, ASCII armored data is returned; * otherwise, binary data is returned. Defaults to * true. * @@ -367,7 +367,7 @@ public function exportPrivateKey($keyId, $armor = true) * the public key. For example, * "Test User (example) ", * "test@example.com" or a hexadecimal string. - * @param boolean $armor optional. If true, ASCII armored data is returned; + * @param bool $armor optional. If true, ASCII armored data is returned; * otherwise, binary data is returned. Defaults to * true. * @@ -528,7 +528,7 @@ public function getKeys($keyId = '') * the key. For example, * "Test User (example) ", * "test@example.com" or a hexadecimal string. - * @param integer $format optional. How the fingerprint should be formatted. + * @param int $format optional. How the fingerprint should be formatted. * Use {@link Crypt_GPG::FORMAT_X509} for X.509 * certificate format, * {@link Crypt_GPG::FORMAT_CANONICAL} for the format @@ -536,8 +536,8 @@ public function getKeys($keyId = '') * {@link Crypt_GPG::FORMAT_NONE} for no formatting. * Defaults to Crypt_GPG::FORMAT_NONE. * - * @return string the fingerprint of the key, or null if no fingerprint - * is found for the given $keyId. + * @return string|null The fingerprint of the key, or null if no fingerprint + * is found for the given $keyId. * * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs. * Use the debug option and file a bug report if these @@ -601,7 +601,7 @@ public function getLastSignatureInfo() * binary. * * @param string $data the data to be encrypted. - * @param boolean $armor optional. If true, ASCII armored data is returned; + * @param bool $armor optional. If true, ASCII armored data is returned; * otherwise, binary data is returned. Defaults to * true. * @@ -632,7 +632,7 @@ public function encrypt($data, $armor = self::ARMOR_ASCII) * which to store the encrypted data. If null * or unspecified, the encrypted data is * returned as a string. - * @param boolean $armor optional. If true, ASCII armored data is + * @param bool $armor optional. If true, ASCII armored data is * returned; otherwise, binary data is * returned. Defaults to true. * @@ -668,12 +668,12 @@ public function encryptFile( * earlier GnuPG versions, you will get an error. Please use * {@link Crypt_GPG::decryptAndVerify()} to verify encrypted-signed data. * - * @param string $data the data to be encrypted and signed. - * @param boolean $armor optional. If true, ASCII armored data is returned; - * otherwise, binary data is returned. Defaults to - * true. + * @param string $data The data to be encrypted and signed. + * @param bool $armor Optional. If true, ASCII armored data is returned; + * otherwise, binary data is returned. Defaults to + * true. * - * @return string the encrypted signed data. + * @return string The encrypted signed data. * * @throws Crypt_GPG_KeyNotFoundException if no encryption key is specified * or if no signing key is specified. See @@ -712,7 +712,7 @@ public function encryptAndSign($data, $armor = self::ARMOR_ASCII) * encrypted, signed data should be stored. If * null or unspecified, the encrypted, signed * data is returned as a string. - * @param boolean $armor optional. If true, ASCII armored data is + * @param bool $armor optional. If true, ASCII armored data is * returned; otherwise, binary data is returned. * Defaults to true. * @@ -826,7 +826,7 @@ public function decryptFile($encryptedFile, $decryptedFile = null) * * @param string $encryptedData the encrypted, signed data to be decrypted * and verified. - * @param boolean $ignoreVerifyErrors enables ignoring of signature + * @param bool $ignoreVerifyErrors enables ignoring of signature * verification errors caused by missing public key * When enabled Crypt_GPG_KeyNotFoundException * will not be thrown. @@ -870,7 +870,7 @@ public function decryptAndVerify($encryptedData, $ignoreVerifyErrors = false) * decrypted data should be written. If null * or unspecified, the decrypted data is * returned in the results array. - * @param boolean $ignoreVerifyErrors enables ignoring of signature + * @param bool $ignoreVerifyErrors enables ignoring of signature * verification errors caused by missing public key * When enabled Crypt_GPG_KeyNotFoundException * will not be thrown. @@ -920,12 +920,12 @@ public function decryptAndVerifyFile($encryptedFile, $decryptedFile = null, $ign * {@link Crypt_GPG::SIGN_MODE_DETACHED}. If not * specified, defaults to * Crypt_GPG::SIGN_MODE_NORMAL. - * @param boolean $armor optional. If true, ASCII armored data is + * @param bool $armor optional. If true, ASCII armored data is * returned; otherwise, binary data is returned. * Defaults to true. This has no effect if the * mode Crypt_GPG::SIGN_MODE_CLEAR is * used. - * @param boolean $textmode optional. If true, line-breaks in signed data + * @param bool $textmode optional. If true, line-breaks in signed data * are normalized. Use this option when signing * e-mail, or for greater compatibility between * systems with different line-break formats. @@ -976,12 +976,12 @@ public function sign( * {@link Crypt_GPG::SIGN_MODE_DETACHED}. If not * specified, defaults to * Crypt_GPG::SIGN_MODE_NORMAL. - * @param boolean $armor optional. If true, ASCII armored data is + * @param bool $armor optional. If true, ASCII armored data is * returned; otherwise, binary data is returned. * Defaults to true. This has no effect if the * mode Crypt_GPG::SIGN_MODE_CLEAR is * used. - * @param boolean $textmode optional. If true, line-breaks in signed data + * @param bool $textmode optional. If true, line-breaks in signed data * are normalized. Use this option when signing * e-mail, or for greater compatibility between * systems with different line-break formats. @@ -1246,7 +1246,7 @@ public function clearPassphrases() /** * Tell if there are encryption keys registered * - * @return boolean True if the data shall be encrypted + * @return bool True if the data shall be encrypted */ public function hasEncryptKeys() { @@ -1256,7 +1256,7 @@ public function hasEncryptKeys() /** * Tell if there are signing keys registered * - * @return boolean True if the data shall be signed + * @return bool True if the data shall be signed */ public function hasSignKeys() { @@ -1279,15 +1279,14 @@ public function getWarnings() * This handles resolving full key objects from the provided * $key value. * - * @param &array $array the array to which the key should be added. - * @param boolean $encrypt whether or not the key must be able to - * encrypt. - * @param boolean $sign whether or not the key must be able to sign. - * @param mixed $key the key to add. This may be a key identifier, + * @param array &$array The array to which the key should be added + * @param bool $encrypt Whether or not the key must be able to + * encrypt + * @param bool $sign Whether or not the key must be able to sign + * @param mixed $key The key to add. This may be a key identifier, * user id, fingerprint, {@link Crypt_GPG_Key} or - * {@link Crypt_GPG_SubKey}. - * @param string $passphrase optional. The passphrase associated with the - * key. + * {@link Crypt_GPG_SubKey} + * @param string $passphrase Optional passphrase associated with the key * * @return void * @@ -1369,8 +1368,8 @@ protected function _addKey(array &$array, $encrypt, $sign, $key, /** * Imports a public or private key into the keyring * - * @param string $key the key to be imported. - * @param boolean $isFile whether or not the input is a filename. + * @param string $key The key to be imported. + * @param bool $isFile Whether or not the input is a filename. * * @return array an associative array containing the following elements: * - fingerprint - the fingerprint of the @@ -1432,10 +1431,10 @@ protected function _importKey($key, $isFile) * * @param string $keyId either the full uid of the key, the email * part of the uid of the key or the key id. - * @param boolean $armor optional. If true, ASCII armored data is returned; + * @param bool $armor optional. If true, ASCII armored data is returned; * otherwise, binary data is returned. Defaults to * true. - * @param boolean $private return private instead of public key + * @param bool $private return private instead of public key * * @return string the key data. * @@ -1479,13 +1478,13 @@ protected function _exportKey($keyId, $armor = true, $private = false) /** * Encrypts data * - * @param string $data the data to encrypt. - * @param boolean $isFile whether or not the data is a filename. - * @param string $outputFile the filename of the file in which to store - * the encrypted data. If null, the encrypted - * data is returned as a string. - * @param boolean $armor if true, ASCII armored data is returned; - * otherwise, binary data is returned. + * @param string $data The data to encrypt. + * @param bool $isFile Whether or not the data is a filename. + * @param string|null $outputFile The filename of the file in which to store + * the encrypted data. If null, the encrypted + * data is returned as a string. + * @param bool $armor If true, ASCII armored data is returned; + * otherwise, binary data is returned. * * @return void|string if the $outputFile parameter is null, a * string containing the encrypted data is returned. @@ -1530,11 +1529,11 @@ protected function _encrypt($data, $isFile, $outputFile, $armor) /** * Decrypts data * - * @param string $data the data to be decrypted. - * @param boolean $isFile whether or not the data is a filename. - * @param string $outputFile the name of the file to which the decrypted - * data should be written. If null, the decrypted - * data is returned as a string. + * @param string $data The data to be decrypted. + * @param bool $isFile Whether or not the data is a filename. + * @param string|null $outputFile The name of the file to which the decrypted + * data should be written. If null, the decrypted + * data is returned as a string. * * @return void|string if the $outputFile parameter is null, a * string containing the decrypted data is returned. @@ -1576,27 +1575,27 @@ protected function _decrypt($data, $isFile, $outputFile) /** * Signs data * - * @param string $data the data to be signed. - * @param boolean $isFile whether or not the data is a filename. - * @param string $outputFile the name of the file in which the signed data - * should be stored. If null, the signed data is - * returned as a string. - * @param int $mode the data signing mode to use. Should be one of - * {@link Crypt_GPG::SIGN_MODE_NORMAL}, - * {@link Crypt_GPG::SIGN_MODE_CLEAR} or - * {@link Crypt_GPG::SIGN_MODE_DETACHED}. - * @param boolean $armor if true, ASCII armored data is returned; - * otherwise, binary data is returned. This has - * no effect if the mode - * Crypt_GPG::SIGN_MODE_CLEAR is - * used. - * @param boolean $textmode if true, line-breaks in signed data be - * normalized. Use this option when signing - * e-mail, or for greater compatibility between - * systems with different line-break formats. - * Defaults to false. This has no effect if the - * mode Crypt_GPG::SIGN_MODE_CLEAR is - * used as clear-signing always uses textmode. + * @param string $data The data to be signed. + * @param bool $isFile Whether or not the data is a filename. + * @param string|null $outputFile The name of the file in which the signed data + * should be stored. If null, the signed data is + * returned as a string. + * @param int $mode The data signing mode to use. Should be one of + * {@link Crypt_GPG::SIGN_MODE_NORMAL}, + * {@link Crypt_GPG::SIGN_MODE_CLEAR} or + * {@link Crypt_GPG::SIGN_MODE_DETACHED}. + * @param bool $armor If true, ASCII armored data is returned; + * otherwise, binary data is returned. This has + * no effect if the mode + * Crypt_GPG::SIGN_MODE_CLEAR is + * used. + * @param bool $textmode If true, line-breaks in signed data be + * normalized. Use this option when signing + * e-mail, or for greater compatibility between + * systems with different line-break formats. + * Defaults to false. This has no effect if the + * mode Crypt_GPG::SIGN_MODE_CLEAR is + * used as clear-signing always uses textmode. * * @return void|string if the $outputFile parameter is null, a * string containing the signed data (or the signature @@ -1670,14 +1669,14 @@ protected function _sign($data, $isFile, $outputFile, $mode, $armor, /** * Encrypts and signs data * - * @param string $data the data to be encrypted and signed. - * @param boolean $isFile whether or not the data is a filename. - * @param string $outputFile the name of the file in which the encrypted, - * signed data should be stored. If null, the - * encrypted, signed data is returned as a - * string. - * @param boolean $armor if true, ASCII armored data is returned; - * otherwise, binary data is returned. + * @param string $data The data to be encrypted and signed. + * @param bool $isFile Whether or not the data is a filename. + * @param string|null $outputFile The name of the file in which the encrypted, + * signed data should be stored. If null, the + * encrypted, signed data is returned as a + * string. + * @param bool $armor If true, ASCII armored data is returned; + * otherwise, binary data is returned. * * @return void|string if the $outputFile parameter is null, a * string containing the encrypted, signed data is @@ -1741,7 +1740,7 @@ protected function _encryptAndSign($data, $isFile, $outputFile, $armor) * Verifies data * * @param string $data the signed data to be verified. - * @param boolean $isFile whether or not the data is a filename. + * @param bool $isFile whether or not the data is a filename. * @param string $signature if verifying a file signed using a detached * signature, this must be the detached signature * data. Otherwise, specify ''. @@ -1797,16 +1796,16 @@ protected function _verify($data, $isFile, $signature) /** * Decrypts and verifies encrypted, signed data * - * @param string $data the encrypted signed data to be decrypted and - * verified. - * @param boolean $isFile whether or not the data is a filename. - * @param string $outputFile the name of the file to which the decrypted - * data should be written. If null, the decrypted - * data is returned in the results array. - * @param boolean $ignoreVerifyErrors enables ignoring of signature verification - * errors caused by missing public key. - * When enabled Crypt_GPG_KeyNotFoundException - * will not be thrown. + * @param string $data The encrypted signed data to be decrypted and + * verified. + * @param bool $isFile Whether or not the data is a filename. + * @param string|null $outputFile The name of the file to which the decrypted + * data should be written. If null, the decrypted + * data is returned in the results array. + * @param bool $ignoreVerifyErrors Enables ignoring of signature verification + * errors caused by missing public key. + * When enabled Crypt_GPG_KeyNotFoundException + * will not be thrown. * * @return array two element array. The array has an element 'data' * containing the decrypted data and an element @@ -1863,9 +1862,9 @@ protected function _decryptAndVerify($data, $isFile, $outputFile, $ignoreVerifyE /** * Prepares command input * - * @param string $data the input data. - * @param boolean $isFile whether or not the input is a filename. - * @param boolean $allowEmpty whether to check if the input is not empty. + * @param string $data The input data + * @param bool $isFile Whether or not the input is a filename + * @param bool $allowEmpty Whether to check if the input is not empty * * @throws Crypt_GPG_NoDataException if the key data is missing. * @throws Crypt_GPG_FileException if the file is not readable. @@ -1899,15 +1898,15 @@ protected function _prepareInput($data, $isFile = false, $allowEmpty = true) /** * Prepares command output * - * @param string $outputFile the name of the file in which the output - * data should be stored. If null, the output - * data is returned as a string. - * @param boolean $input the input resource, in case it would need - * to be released (closed) on exception. + * @param string|null $outputFile The name of the file in which the output + * data should be stored. If null, the output + * data is returned as a string. + * @param resource $input The input resource, in case it would need + * to be released (closed) on exception. * * @throws Crypt_GPG_FileException if the file is not writeable. * - * @return string The command output + * @return string|resource The command output */ protected function _prepareOutput($outputFile, $input = null) { diff --git a/Crypt/GPG/Engine.php b/Crypt/GPG/Engine.php index bab3dfb..62eade4 100644 --- a/Crypt/GPG/Engine.php +++ b/Crypt/GPG/Engine.php @@ -149,7 +149,7 @@ class Crypt_GPG_Engine * * Strict mode is disabled by default. * - * @var boolean + * @var bool * @see Crypt_GPG_Engine::__construct() */ private $_strict = false; @@ -197,7 +197,7 @@ class Crypt_GPG_Engine * * Only used for GnuPG 2.1.x * - * @var string + * @var string|false|null * @see Crypt_GPG_Engine::__construct() * @see Crypt_GPG_Engine::_getGPGConf() */ @@ -293,28 +293,28 @@ class Crypt_GPG_Engine /** * A handle for the GPG process * - * @var resource + * @var resource|null */ private $_process = null; /** * A handle for the gpg-agent process * - * @var resource + * @var resource|null */ private $_agentProcess = null; /** * GPG agent daemon socket and PID for running gpg-agent * - * @var string + * @var string|null */ private $_agentInfo = null; /** * Whether or not the operating system is Darwin (OS X) * - * @var boolean + * @var bool */ private $_isDarwin = false; @@ -357,7 +357,7 @@ class Crypt_GPG_Engine /** * A status/error handler * - * @var Crypt_GPG_ProcessHanler + * @var Crypt_GPG_ProcessHandler|null */ private $_processHandler = null; @@ -382,7 +382,7 @@ class Crypt_GPG_Engine * * This is data to send to GPG. Either a string or a stream resource. * - * @var string|resource + * @var string|resource|null * @see Crypt_GPG_Engine::setInput() */ private $_input = null; @@ -392,7 +392,7 @@ class Crypt_GPG_Engine * * Either a string or a stream resource. * - * @var string|resource + * @var string|resource|null * @see Crypt_GPG_Engine::setMessage() */ private $_message = null; @@ -663,7 +663,7 @@ public function __destruct() * subprocess. The handler method must accept the error line to be handled * as its first parameter. * - * @param callback $callback the callback method to use. + * @param callable $callback the callback method to use. * @param array $args optional. Additional arguments to pass as * parameters to the callback method. * @@ -684,7 +684,7 @@ public function addErrorHandler($callback, array $args = array()) * GPG subprocess. The handler method must accept the status line to be * handled as its first parameter. * - * @param callback $callback the callback method to use. + * @param callable $callback the callback method to use. * @param array $args optional. Additional arguments to pass as * parameters to the callback method. * @@ -780,10 +780,9 @@ public function run() /** * Sets the input source for the current GPG operation * - * @param &string|resource $input either a reference to the string + * @param string|resource &$input Either a reference to the string * containing the input data or an open - * stream resource containing the input - * data. + * stream resource containing the input data * * @return void */ @@ -797,10 +796,9 @@ public function setInput(&$input) * * Detached signature data should be specified here. * - * @param &string|resource $message either a reference to the string + * @param string|resource &$message Either a reference to the string * containing the message data or an open - * stream resource containing the message - * data. + * stream resource containing the message data * * @return void */ @@ -812,10 +810,10 @@ public function setMessage(&$message) /** * Sets the output destination for the current GPG operation * - * @param &string|resource $output either a reference to the string in + * @param string|resource &$output Either a reference to the string in * which to store GPG output or an open * stream resource to which the output data - * should be written. + * should be written * * @return void */ @@ -908,7 +906,7 @@ public function setOptions(array $options) * Use the debug option and file a bug report if these * exceptions occur. * - * @throws Crypt_GPG_UnsupportedException if the provided binary is not + * @throws Crypt_GPG_Exception if the provided binary is not * GnuPG or if the GnuPG version is less than 1.0.2. */ public function getVersion() @@ -1715,7 +1713,7 @@ private function _closeSubprocess() // proc_close() can return -1 in some cases, // get the real exit code from the process status - if ($exitCode < 0 && $status && !$status['running']) { + if ($exitCode < 0 && !$status['running']) { $exitCode = $status['exitcode']; } @@ -1804,8 +1802,7 @@ private function _closeAgentLaunchProcess() * If the pipe is already closed, it is ignored. If the pipe is open, it * is flushed and then closed. * - * @param integer $pipeNumber the file descriptor number of the pipe to - * close. + * @param int $pipeNumber The file descriptor number of the pipe to close * * @return void */ @@ -1925,7 +1922,7 @@ private function _findBinary($name) /** * Gets the location of the PinEntry script * - * @return string the location of the PinEntry script. + * @return string|null the location of the PinEntry script. */ private function _getPinEntry() { @@ -1943,6 +1940,8 @@ private function _getPinEntry() return $path . $ds . 'crypt-gpg-pinentry'; } } + + return null; } /** diff --git a/Crypt/GPG/Exceptions.php b/Crypt/GPG/Exceptions.php index 4950560..4dc415a 100644 --- a/Crypt/GPG/Exceptions.php +++ b/Crypt/GPG/Exceptions.php @@ -80,9 +80,9 @@ class Crypt_GPG_FileException extends Crypt_GPG_Exception /** * Creates a new Crypt_GPG_FileException * - * @param string $message an error message. - * @param integer $code a user defined error code. - * @param string $filename the name of the file that caused this exception. + * @param string $message An error message. + * @param int $code A user defined error code. + * @param string $filename The name of the file that caused this exception. */ public function __construct($message, $code = 0, $filename = '') { @@ -128,10 +128,10 @@ class Crypt_GPG_OpenSubprocessException extends Crypt_GPG_Exception /** * Creates a new Crypt_GPG_OpenSubprocessException * - * @param string $message an error message. - * @param integer $code a user defined error code. - * @param string $command the command that was called to open the - * new subprocess. + * @param string $message An error message. + * @param int $code A user defined error code. + * @param string $command The command that was called to open the + * new subprocess. * * @see Crypt_GPG::_openSubprocess() */ @@ -176,9 +176,9 @@ class Crypt_GPG_InvalidOperationException extends Crypt_GPG_Exception /** * Creates a new Crypt_GPG_OpenSubprocessException * - * @param string $message an error message. - * @param integer $code a user defined error code. - * @param string $operation the operation. + * @param string $message An error message. + * @param int $code A user defined error code. + * @param string $operation The operation. */ public function __construct($message, $code = 0, $operation = '') { @@ -222,9 +222,9 @@ class Crypt_GPG_KeyNotFoundException extends Crypt_GPG_Exception /** * Creates a new Crypt_GPG_KeyNotFoundException * - * @param string $message an error message. - * @param integer $code a user defined error code. - * @param string $keyId the key identifier of the key. + * @param string $message An error message. + * @param int $code A user defined error code. + * @param string $keyId The key identifier of the key. */ public function __construct($message, $code = 0, $keyId= '') { @@ -291,12 +291,12 @@ class Crypt_GPG_BadPassphraseException extends Crypt_GPG_Exception /** * Creates a new Crypt_GPG_BadPassphraseException * - * @param string $message an error message. - * @param integer $code a user defined error code. - * @param array $badPassphrases an array containing user ids of keys - * for which the passphrase is incorrect. - * @param array $missingPassphrases an array containing user ids of keys - * for which the passphrase is missing. + * @param string $message An error message. + * @param int $code A user defined error code. + * @param array $badPassphrases An array containing user ids of keys + * for which the passphrase is incorrect. + * @param array $missingPassphrases An array containing user ids of keys + * for which the passphrase is missing. */ public function __construct($message, $code = 0, array $badPassphrases = array(), array $missingPassphrases = array() @@ -355,10 +355,10 @@ class Crypt_GPG_DeletePrivateKeyException extends Crypt_GPG_Exception /** * Creates a new Crypt_GPG_DeletePrivateKeyException * - * @param string $message an error message. - * @param integer $code a user defined error code. - * @param string $keyId the key identifier of the public key that was - * attempted to delete. + * @param string $message An error message. + * @param int $code A user defined error code. + * @param string $keyId The key identifier of the public key that was + * attempted to delete. * * @see Crypt_GPG::deletePublicKey() */ @@ -410,32 +410,32 @@ class Crypt_GPG_InvalidKeyParamsException extends Crypt_GPG_Exception /** * The key algorithm * - * @var integer + * @var int */ private $_algorithm = 0; /** * The key size * - * @var integer + * @var int */ private $_size = 0; /** * The key usage * - * @var integer + * @var int */ private $_usage = 0; /** * Creates a new Crypt_GPG_InvalidKeyParamsException * - * @param string $message an error message. - * @param integer $code a user defined error code. - * @param string $algorithm the key algorithm. - * @param string $size the key size. - * @param string $usage the key usage. + * @param string $message An error message. + * @param int $code A user defined error code. + * @param int $algorithm The key algorithm. + * @param int $size The key size. + * @param int $usage The key usage. */ public function __construct( $message, @@ -454,7 +454,7 @@ public function __construct( /** * Gets the key algorithm * - * @return integer the key algorithm. + * @return int The key algorithm. */ public function getAlgorithm() { @@ -464,7 +464,7 @@ public function getAlgorithm() /** * Gets the key size * - * @return integer the key size. + * @return int The key size. */ public function getSize() { @@ -474,7 +474,7 @@ public function getSize() /** * Gets the key usage * - * @return integer the key usage. + * @return int The key usage. */ public function getUsage() { diff --git a/Crypt/GPG/KeyGenerator.php b/Crypt/GPG/KeyGenerator.php index 7bd5ca0..b98206a 100644 --- a/Crypt/GPG/KeyGenerator.php +++ b/Crypt/GPG/KeyGenerator.php @@ -70,7 +70,7 @@ class Crypt_GPG_KeyGenerator extends Crypt_GPGAbstract /** * The expiration date of generated keys * - * @var integer + * @var int * * @see Crypt_GPG_KeyGenerator::setExpirationDate() */ @@ -88,7 +88,7 @@ class Crypt_GPG_KeyGenerator extends Crypt_GPGAbstract /** * The algorithm for generated primary keys * - * @var integer + * @var int * * @see Crypt_GPG_KeyGenerator::setKeyParams() */ @@ -97,7 +97,7 @@ class Crypt_GPG_KeyGenerator extends Crypt_GPGAbstract /** * The size of generated primary keys * - * @var integer + * @var int * * @see Crypt_GPG_KeyGenerator::setKeyParams() */ @@ -109,7 +109,7 @@ class Crypt_GPG_KeyGenerator extends Crypt_GPGAbstract * This is a bitwise combination of the usage constants in * {@link Crypt_GPG_SubKey}. * - * @var integer + * @var int * * @see Crypt_GPG_KeyGenerator::setKeyParams() */ @@ -118,7 +118,7 @@ class Crypt_GPG_KeyGenerator extends Crypt_GPGAbstract /** * The algorithm for generated sub-keys * - * @var integer + * @var int * * @see Crypt_GPG_KeyGenerator::setSubKeyParams() */ @@ -127,7 +127,7 @@ class Crypt_GPG_KeyGenerator extends Crypt_GPGAbstract /** * The size of generated sub-keys * - * @var integer + * @var int * * @see Crypt_GPG_KeyGenerator::setSubKeyParams() */ @@ -139,7 +139,7 @@ class Crypt_GPG_KeyGenerator extends Crypt_GPGAbstract * This is a bitwise combination of the usage constants in * {@link Crypt_GPG_SubKey}. * - * @var integer + * @var int * * @see Crypt_GPG_KeyGenerator::setSubKeyParams() */ @@ -179,21 +179,21 @@ public function __construct(array $options = array()) /** * Sets the expiration date of generated keys * - * @param string|integer $date either a string that may be parsed by - * PHP's strtotime() function, or an integer - * timestamp representing the number of seconds - * since the UNIX epoch. This date must be at - * least one date in the future. Keys that - * expire in the past may not be generated. Use - * an expiration date of 0 for keys that do not - * expire. + * @param string|int $date Either a string that may be parsed by + * PHP's strtotime() function, or an integer + * timestamp representing the number of seconds + * since the UNIX epoch. This date must be at + * least one date in the future. Keys that + * expire in the past may not be generated. Use + * an expiration date of 0 for keys that do not + * expire. * - * @throws InvalidArgumentException if the date is not a valid format, or + * @throws InvalidArgumentException If the date is not a valid format, or * if the date is not at least one day in * the future, or if the date is greater * than 2038-01-19T03:14:07. * - * @return Crypt_GPG_KeyGenerator the current object, for fluent interface. + * @return Crypt_GPG_KeyGenerator The current object, for fluent interface. */ public function setExpirationDate($date) { @@ -248,22 +248,22 @@ public function setPassphrase($passphrase) /** * Sets the parameters for the primary key of generated key-pairs * - * @param integer $algorithm the algorithm used by the key. This should be - * one of the Crypt_GPG_SubKey::ALGORITHM_* - * constants. - * @param integer $size optional. The size of the key. Different - * algorithms have different size requirements. - * If not specified, the default size for the - * specified algorithm will be used. If an - * invalid key size is used, GnuPG will do its - * best to round it to a valid size. - * @param integer $usage optional. A bitwise combination of key usages. - * If not specified, the primary key will be used - * only to sign and certify. This is the default - * behavior of GnuPG in interactive mode. Use - * the Crypt_GPG_SubKey::USAGE_* constants here. - * The primary key may be used to certify even - * if the certify usage is not specified. + * @param int $algorithm the algorithm used by the key. This should be + * one of the Crypt_GPG_SubKey::ALGORITHM_* + * constants. + * @param int $size optional. The size of the key. Different + * algorithms have different size requirements. + * If not specified, the default size for the + * specified algorithm will be used. If an + * invalid key size is used, GnuPG will do its + * best to round it to a valid size. + * @param int $usage optional. A bitwise combination of key usages. + * If not specified, the primary key will be used + * only to sign and certify. This is the default + * behavior of GnuPG in interactive mode. Use + * the Crypt_GPG_SubKey::USAGE_* constants here. + * The primary key may be used to certify even + * if the certify usage is not specified. * * @return Crypt_GPG_KeyGenerator the current object, for fluent interface. */ @@ -322,24 +322,24 @@ public function setKeyParams($algorithm, $size = 0, $usage = 0) /** * Sets the parameters for the sub-key of generated key-pairs * - * @param integer $algorithm the algorithm used by the key. This should be - * one of the Crypt_GPG_SubKey::ALGORITHM_* - * constants. - * @param integer $size optional. The size of the key. Different - * algorithms have different size requirements. - * If not specified, the default size for the - * specified algorithm will be used. If an - * invalid key size is used, GnuPG will do its - * best to round it to a valid size. - * @param integer $usage optional. A bitwise combination of key usages. - * If not specified, the sub-key will be used - * only to encrypt. This is the default behavior - * of GnuPG in interactive mode. Use the - * Crypt_GPG_SubKey::USAGE_* constants here. - * - * @return Crypt_GPG_KeyGenerator the current object, for fluent interface. + * @param int $algorithm The algorithm used by the key. This should be + * one of the Crypt_GPG_SubKey::ALGORITHM_* + * constants. + * @param int $size Optional size of the key. Different + * algorithms have different size requirements. + * If not specified, the default size for the + * specified algorithm will be used. If an + * invalid key size is used, GnuPG will do its + * best to round it to a valid size. + * @param int $usage Optional bitwise combination of key usages. + * If not specified, the sub-key will be used + * only to encrypt. This is the default behavior + * of GnuPG in interactive mode. Use the + * Crypt_GPG_SubKey::USAGE_* constants here. + * + * @return Crypt_GPG_KeyGenerator The current object, for fluent interface. */ - public function setSubKeyParams($algorithm, $size = '', $usage = 0) + public function setSubKeyParams($algorithm, $size = 0, $usage = 0) { $algorithm = intval($algorithm); @@ -535,11 +535,11 @@ public function generateKey($name, $email = '', $comment = '') * {@link http://www.gnupg.org/download/ GPG distribution} for detailed * information on the key usage format. * - * @param integer $usage a bitwise combination of the key usages. This is - * a combination of the Crypt_GPG_SubKey::USAGE_* - * constants. + * @param int $usage A bitwise combination of the key usages. This is + * a combination of the Crypt_GPG_SubKey::USAGE_* + * constants. * - * @return string the key usage string. + * @return string The key usage string. */ protected function getUsage($usage) { diff --git a/Crypt/GPG/PinEntry.php b/Crypt/GPG/PinEntry.php index 5a70f9e..b4e517d 100644 --- a/Crypt/GPG/PinEntry.php +++ b/Crypt/GPG/PinEntry.php @@ -97,28 +97,28 @@ class Crypt_GPG_PinEntry /** * File handle for the input stream * - * @var resource + * @var resource|null */ protected $stdin = null; /** * File handle for the output stream * - * @var resource + * @var resource|null */ protected $stdout = null; /** * File handle for the log file if a log file is used * - * @var resource + * @var resource|null */ protected $logFile = null; /** * Whether or not this pinentry is finished and is exiting * - * @var boolean + * @var bool */ protected $moribund = false; @@ -130,7 +130,7 @@ class Crypt_GPG_PinEntry * - {@link Crypt_GPG_PinEntry::VERBOSITY_ERRORS}, or * - {@link Crypt_GPG_PinEntry::VERBOSITY_ALL} * - * @var integer + * @var int */ protected $verbosity = self::VERBOSITY_NONE; @@ -212,8 +212,8 @@ public function __invoke() $this->disconnect(); - } catch (Console_CommandLineException $e) { - $this->log($e->getMessage() . PHP_EOL, slf::VERBOSITY_ERRORS); + } catch (Console_CommandLine_Exception $e) { + $this->log($e->getMessage() . PHP_EOL, self::VERBOSITY_ERRORS); exit(1); } catch (Exception $e) { $this->log($e->getMessage() . PHP_EOL, self::VERBOSITY_ERRORS); @@ -232,13 +232,13 @@ public function __invoke() * - {@link Crypt_GPG_PinEntry::VERBOSITY_ALL} - log everything, including * the assuan protocol. * - * @param integer $verbosity the level of verbosity of this pinentry. + * @param int $verbosity The level of verbosity of this pinentry. * * @return Crypt_GPG_PinEntry the current object, for fluent interface. */ public function setVerbosity($verbosity) { - $this->verbosity = (integer)$verbosity; + $this->verbosity = (int) $verbosity; return $this; } @@ -280,7 +280,7 @@ public function setLogFilename($filename) * Detects whether or not this package is PEAR-installed and appropriately * locates the XML UI definition. * - * @return string the location of the CLI user-interface definition XML. + * @return string|null The location of the CLI user-interface definition XML. */ protected function getUIXML() { @@ -298,6 +298,8 @@ protected function getUIXML() return $path . $ds . 'pinentry-cli.xml'; } } + + return null; } /** @@ -316,9 +318,9 @@ protected function getCommandLineParser() * If a log file is used, the message is written to the log. Otherwise, * the message is sent to STDERR. * - * @param string $data the message to log. - * @param integer $level the verbosity level above which the message should - * be logged. + * @param string $data The message to log. + * @param int $level The verbosity level above which the message should + * be logged. * * @return Crypt_GPG_PinEntry the current object, for fluent interface. */ @@ -405,7 +407,7 @@ protected function parseCommand($line) return $this->sendGetInfo($data); case 'GETPIN': - return $this->sendGetPin($data); + return $this->sendGetPin(); case 'RESET': return $this->sendReset(); @@ -611,8 +613,6 @@ protected function sendGetInfo($data) default: return $this->send($this->getOK()); } - - return $this; } /** @@ -731,7 +731,7 @@ protected function getWordWrappedData($data, $prefix) $line = $prefix . ' ' . mb_strcut($data, 0, 996, 'utf-8') . "\\\n"; $lines[] = $line; $lineLength = mb_strlen($line, '8bit') - 1; - $dataLength = mb_substr($data, '8bit'); + $dataLength = mb_strlen($data, '8bit'); $data = mb_substr( $data, $lineLength, diff --git a/Crypt/GPG/ProcessControl.php b/Crypt/GPG/ProcessControl.php index a8c2210..4843f59 100644 --- a/Crypt/GPG/ProcessControl.php +++ b/Crypt/GPG/ProcessControl.php @@ -48,14 +48,14 @@ class Crypt_GPG_ProcessControl /** * The PID (process identifier) being monitored * - * @var integer + * @var int */ protected $pid; /** * Creates a new process controller from the given PID (process identifier) * - * @param integer $pid the PID (process identifier). + * @param int $pid The PID (process identifier). */ public function __construct($pid) { @@ -65,7 +65,7 @@ public function __construct($pid) /** * Gets the PID (process identifier) being controlled * - * @return integer the PID being controlled. + * @return int The PID being controlled. */ public function getPid() { @@ -79,7 +79,7 @@ public function getPid() * is used. Otherwise ps is used on UNIX-like systems and * tasklist on Windows. * - * @return boolean true if the process is running, false if not. + * @return bool True if the process is running, false if not. */ public function isRunning() { diff --git a/Crypt/GPG/ProcessHandler.php b/Crypt/GPG/ProcessHandler.php index dcfaee1..d1898c2 100644 --- a/Crypt/GPG/ProcessHandler.php +++ b/Crypt/GPG/ProcessHandler.php @@ -72,7 +72,7 @@ class Crypt_GPG_ProcessHandler /** * The error code of the current operation * - * @var integer + * @var int */ protected $errorCode = Crypt_GPG::ERROR_NONE; @@ -82,7 +82,7 @@ class Crypt_GPG_ProcessHandler * If this is not zero when the GPG command is completed, the error code is * set to {@link Crypt_GPG::ERROR_MISSING_PASSPHRASE}. * - * @var integer + * @var int */ protected $needPassphrase = 0; @@ -606,7 +606,7 @@ public function throwException($exitcode = 0) 'Unknown error deleting key. ' . $note, $code ); } - break; + break; // @phpstan-ignore-line case 'import': switch ($code) { @@ -624,7 +624,7 @@ public function throwException($exitcode = 0) 'Unknown error importing GPG key. ' . $note, $code ); } - break; + break; // @phpstan-ignore-line case 'export': case 'export-secret-keys': @@ -638,7 +638,7 @@ public function throwException($exitcode = 0) 'Unknown error exporting a key. ' . $note, $code ); } - break; + break; // @phpstan-ignore-line case 'encrypt': case 'sign': @@ -668,7 +668,7 @@ public function throwException($exitcode = 0) "Unknown error {$this->operation}ing data. $note", $code ); } - break; + break; // @phpstan-ignore-line case 'verify': switch ($code) { diff --git a/Crypt/GPG/Signature.php b/Crypt/GPG/Signature.php index 9df7898..dfac77f 100644 --- a/Crypt/GPG/Signature.php +++ b/Crypt/GPG/Signature.php @@ -83,7 +83,7 @@ class Crypt_GPG_Signature * * This is a Unix timestamp. * - * @var integer + * @var int */ private $_creationDate = 0; @@ -93,7 +93,7 @@ class Crypt_GPG_Signature * This is a Unix timestamp. If this signature does not expire, this will * be zero. * - * @var integer + * @var int */ private $_expirationDate = 0; @@ -107,7 +107,7 @@ class Crypt_GPG_Signature /** * Whether or not this signature is valid * - * @var boolean + * @var bool */ private $_isValid = false; @@ -124,12 +124,12 @@ class Crypt_GPG_Signature * characters. * - string keyId - the id of the key used to create the * the signature. - * - integer creation - the date the signature was created. + * - int creation - the date the signature was created. * This is a UNIX timestamp. - * - integer expiration - the date the signature expired. This + * - int expiration - the date the signature expired. This * is a UNIX timestamp. If the signature * does not expire, use 0. - * - boolean valid - whether or not the signature is valid. + * - bool valid - whether or not the signature is valid. * - string userId - the user id associated with the * signature. This may also be a * {@link Crypt_GPG_UserId} object. @@ -314,8 +314,8 @@ public function setKeyId($id) /** * Sets the creation date of this signature * - * @param integer $creationDate the creation date of this signature. This - * is a Unix timestamp. + * @param int $creationDate The creation date of this signature. This + * is a Unix timestamp. * * @return Crypt_GPG_Signature the current object, for fluent interface. */ @@ -328,9 +328,9 @@ public function setCreationDate($creationDate) /** * Sets the expiration date of this signature * - * @param integer $expirationDate the expiration date of this signature. - * This is a Unix timestamp. Specify zero if - * this signature does not expire. + * @param int $expirationDate the expiration date of this signature. + * This is a Unix timestamp. Specify zero if + * this signature does not expire. * * @return Crypt_GPG_Signature the current object, for fluent interface. */ @@ -357,8 +357,8 @@ public function setUserId(Crypt_GPG_UserId $userId) /** * Sets whether or not this signature is valid * - * @param boolean $isValid true if this signature is valid and false if it - * is not. + * @param bool $isValid True if this signature is valid and false if it + * is not. * * @return Crypt_GPG_Signature the current object, for fluent interface. */ diff --git a/Crypt/GPG/SignatureCreationInfo.php b/Crypt/GPG/SignatureCreationInfo.php index 9d3b028..b229f94 100644 --- a/Crypt/GPG/SignatureCreationInfo.php +++ b/Crypt/GPG/SignatureCreationInfo.php @@ -32,14 +32,14 @@ class Crypt_GPG_SignatureCreationInfo * - {@link Crypt_GPG::SIGN_MODE_CLEAR} * - {@link Crypt_GPG::SIGN_MODE_DETACHED} * - * @var integer + * @var int */ protected $mode; /** * Public Key algorithm * - * @var integer + * @var int */ protected $pkAlgorithm; @@ -47,7 +47,7 @@ class Crypt_GPG_SignatureCreationInfo * Algorithm to hash the data * * @see RFC 2440 / 9.4. Hash Algorithm - * @var integer + * @var int */ protected $hashAlgorithm; @@ -61,7 +61,7 @@ class Crypt_GPG_SignatureCreationInfo /** * Unix timestamp when the signature was created * - * @var integer + * @var int */ protected $timestamp; @@ -75,7 +75,7 @@ class Crypt_GPG_SignatureCreationInfo /** * If the line given to the constructor was valid * - * @var boolean + * @var bool */ protected $valid; @@ -153,7 +153,7 @@ public function __construct($sigCreatedLine = null) * - {@link Crypt_GPG::SIGN_MODE_CLEAR} * - {@link Crypt_GPG::SIGN_MODE_DETACHED} * - * @return integer + * @return int */ public function getMode() { @@ -163,7 +163,7 @@ public function getMode() /** * Return the public key algorithm used. * - * @return integer + * @return int */ public function getPkAlgorithm() { @@ -173,7 +173,7 @@ public function getPkAlgorithm() /** * Return the hash algorithm used to hash the data to sign. * - * @return integer + * @return int */ public function getHashAlgorithm() { @@ -196,7 +196,7 @@ public function getHashAlgorithmName() /** * Return the timestamp at which the signature was created * - * @return integer + * @return int */ public function getTimestamp() { @@ -216,7 +216,7 @@ public function getKeyFingerprint() /** * Tell if the fingerprint line given to the constructor was valid * - * @return boolean + * @return bool */ public function isValid() { diff --git a/Crypt/GPG/SubKey.php b/Crypt/GPG/SubKey.php index 9bb7525..8998b7d 100644 --- a/Crypt/GPG/SubKey.php +++ b/Crypt/GPG/SubKey.php @@ -101,7 +101,7 @@ class Crypt_GPG_SubKey * * The value is one of the Crypt_GPG_SubKey::ALGORITHM_* constants. * - * @var integer + * @var int */ private $_algorithm = 0; @@ -115,7 +115,7 @@ class Crypt_GPG_SubKey /** * Length of this sub-key in bits * - * @var integer + * @var int */ private $_length = 0; @@ -124,9 +124,9 @@ class Crypt_GPG_SubKey * * This is a Unix timestamp. * - * @var DateTime + * @var DateTime|null */ - private $_creationDate; + private $_creationDate = null; /** * Date this sub-key expires @@ -134,9 +134,9 @@ class Crypt_GPG_SubKey * This is a Unix timestamp. If this sub-key does not expire, this will be * null. * - * @var DateTime + * @var DateTime|null */ - private $_expirationDate; + private $_expirationDate = null; /** * Contains usage flags of this sub-key @@ -148,14 +148,14 @@ class Crypt_GPG_SubKey /** * Whether or not the private key for this sub-key exists in the keyring * - * @var boolean + * @var bool */ private $_hasPrivate = false; /** * Whether or not this sub-key is revoked * - * @var boolean + * @var bool */ private $_isRevoked = false; @@ -165,27 +165,27 @@ class Crypt_GPG_SubKey * Sub-keys can be initialized from an array of named values. Available * names are: * - * - string id - the key id of the sub-key. - * - integer algorithm - the encryption algorithm of the - * sub-key. - * - string fingerprint - the fingerprint of the sub-key. The - * fingerprint should not contain - * formatting characters. - * - integer length - the length of the sub-key in bits. - * - integer creation - the date the sub-key was created. - * This is a UNIX timestamp. - * - integer expiration - the date the sub-key expires. This - * is a UNIX timestamp. If the sub-key - * does not expire, use 0. - * - boolean canSign - whether or not the sub-key can be - * used to sign data. - * - boolean canEncrypt - whether or not the sub-key can be - * used to encrypt data. - * - integer usage - the sub-key usage flags - * - boolean hasPrivate - whether or not the private key for - * the sub-key exists in the keyring. - * - boolean isRevoked - whether or not this sub-key is - * revoked. + * - string id - the key id of the sub-key. + * - int algorithm - the encryption algorithm of the + * sub-key. + * - string fingerprint - the fingerprint of the sub-key. The + * fingerprint should not contain + * formatting characters. + * - int length - the length of the sub-key in bits. + * - int creation - the date the sub-key was created. + * This is a UNIX timestamp. + * - int expiration - the date the sub-key expires. This + * is a UNIX timestamp. If the sub-key + * does not expire, use 0. + * - bool canSign - whether or not the sub-key can be + * used to sign data. + * - bool canEncrypt - whether or not the sub-key can be + * used to encrypt data. + * - int usage - the sub-key usage flags + * - bool hasPrivate - whether or not the private key for + * the sub-key exists in the keyring. + * - bool isRevoked - whether or not this sub-key is + * revoked. * * @param Crypt_GPG_SubKey|string|array|null $key Either an existing sub-key object, * which is copied; a sub-key string, @@ -263,7 +263,7 @@ public function __construct($key = null) /** * Gets the id of this sub-key * - * @return string the id of this sub-key. + * @return string The id of this sub-key. */ public function getId() { @@ -276,7 +276,7 @@ public function getId() * The algorithm should be one of the Crypt_GPG_SubKey::ALGORITHM_* * constants. * - * @return integer the algorithm used by this sub-key. + * @return int The algorithm used by this sub-key. */ public function getAlgorithm() { @@ -289,7 +289,7 @@ public function getAlgorithm() * This is a Unix timestamp. Warning: On 32-bit systems it returns * invalid value for dates after 2038-01-19. Use getCreationDateTime(). * - * @return integer the creation date of this sub-key. + * @return int The creation date of this sub-key. */ public function getCreationDate() { @@ -313,7 +313,7 @@ public function getCreationDateTime() * zero. Warning: On 32-bit systems it returns invalid value for dates * after 2038-01-19. Use getExpirationDateTime(). * - * @return integer the date this sub-key expires. + * @return int The date this sub-key expires. */ public function getExpirationDate() { @@ -323,7 +323,7 @@ public function getExpirationDate() /** * Gets the date-time (UTC) this sub-key expires * - * @return integer the date this sub-key expires. + * @return DateTime|null The date this sub-key expires. */ public function getExpirationDateTime() { @@ -333,7 +333,7 @@ public function getExpirationDateTime() /** * Gets the fingerprint of this sub-key * - * @return string the fingerprint of this sub-key. + * @return string The fingerprint of this sub-key. */ public function getFingerprint() { @@ -343,7 +343,7 @@ public function getFingerprint() /** * Gets the length of this sub-key in bits * - * @return integer the length of this sub-key in bits. + * @return int The length of this sub-key in bits. */ public function getLength() { @@ -353,8 +353,8 @@ public function getLength() /** * Gets whether or not this sub-key can sign data * - * @return boolean true if this sub-key can sign data and false if this - * sub-key can not sign data. + * @return bool True if this sub-key can sign data and false if this + * sub-key can not sign data. */ public function canSign() { @@ -364,8 +364,8 @@ public function canSign() /** * Gets whether or not this sub-key can encrypt data * - * @return boolean true if this sub-key can encrypt data and false if this - * sub-key can not encrypt data. + * @return bool True if this sub-key can encrypt data and false if this + * sub-key can not encrypt data. */ public function canEncrypt() { @@ -386,8 +386,8 @@ public function usage() * Gets whether or not the private key for this sub-key exists in the * keyring * - * @return boolean true the private key for this sub-key exists in the - * keyring and false if it does not. + * @return bool True the private key for this sub-key exists in the + * keyring and false if it does not. */ public function hasPrivate() { @@ -397,7 +397,7 @@ public function hasPrivate() /** * Gets whether or not this sub-key is revoked * - * @return boolean true if this sub-key is revoked and false if it is not. + * @return bool True if this sub-key is revoked and false if it is not. */ public function isRevoked() { @@ -409,9 +409,9 @@ public function isRevoked() * * The creation date is a Unix timestamp or DateTime object. * - * @param integer|DateTime $creationDate the creation date of this sub-key. + * @param int|DateTime $creationDate The creation date of this sub-key. * - * @return Crypt_GPG_SubKey the current object, for fluent interface. + * @return Crypt_GPG_SubKey The current object, for fluent interface. */ public function setCreationDate($creationDate) { @@ -436,9 +436,9 @@ public function setCreationDate($creationDate) * The expiration date is a Unix timestamp. Specify zero if this sub-key * does not expire. * - * @param integer|DateTime $expirationDate the expiration date of this sub-key. + * @param int|DateTime $expirationDate The expiration date of this sub-key. * - * @return Crypt_GPG_SubKey the current object, for fluent interface. + * @return Crypt_GPG_SubKey The current object, for fluent interface. */ public function setExpirationDate($expirationDate) { @@ -460,9 +460,9 @@ public function setExpirationDate($expirationDate) /** * Sets the id of this sub-key * - * @param string $id the id of this sub-key. + * @param string $id The id of this sub-key. * - * @return Crypt_GPG_SubKey the current object, for fluent interface. + * @return Crypt_GPG_SubKey The current object, for fluent interface. */ public function setId($id) { @@ -473,9 +473,9 @@ public function setId($id) /** * Sets the algorithm used by this sub-key * - * @param integer $algorithm the algorithm used by this sub-key. + * @param int $algorithm The algorithm used by this sub-key. * - * @return Crypt_GPG_SubKey the current object, for fluent interface. + * @return Crypt_GPG_SubKey The current object, for fluent interface. */ public function setAlgorithm($algorithm) { @@ -486,9 +486,9 @@ public function setAlgorithm($algorithm) /** * Sets the fingerprint of this sub-key * - * @param string $fingerprint the fingerprint of this sub-key. + * @param string $fingerprint The fingerprint of this sub-key. * - * @return Crypt_GPG_SubKey the current object, for fluent interface. + * @return Crypt_GPG_SubKey The current object, for fluent interface. */ public function setFingerprint($fingerprint) { @@ -499,9 +499,9 @@ public function setFingerprint($fingerprint) /** * Sets the length of this sub-key in bits * - * @param integer $length the length of this sub-key in bits. + * @param int $length The length of this sub-key in bits. * - * @return Crypt_GPG_SubKey the current object, for fluent interface. + * @return Crypt_GPG_SubKey The current object, for fluent interface. */ public function setLength($length) { @@ -512,10 +512,10 @@ public function setLength($length) /** * Sets whether or not this sub-key can sign data * - * @param boolean $canSign true if this sub-key can sign data and false if - * it can not. + * @param bool $canSign True if this sub-key can sign data and false if + * it can not. * - * @return Crypt_GPG_SubKey the current object, for fluent interface. + * @return Crypt_GPG_SubKey The current object, for fluent interface. */ public function setCanSign($canSign) { @@ -531,10 +531,10 @@ public function setCanSign($canSign) /** * Sets whether or not this sub-key can encrypt data * - * @param boolean $canEncrypt true if this sub-key can encrypt data and - * false if it can not. + * @param bool $canEncrypt True if this sub-key can encrypt data and + * false if it can not. * - * @return Crypt_GPG_SubKey the current object, for fluent interface. + * @return Crypt_GPG_SubKey The current object, for fluent interface. */ public function setCanEncrypt($canEncrypt) { @@ -550,9 +550,9 @@ public function setCanEncrypt($canEncrypt) /** * Sets usage flags of the sub-key * - * @param integer $usage Usage flags + * @param int $usage Usage flags * - * @return Crypt_GPG_SubKey the current object, for fluent interface. + * @return Crypt_GPG_SubKey The current object, for fluent interface. */ public function setUsage($usage) { @@ -564,11 +564,11 @@ public function setUsage($usage) * Sets whether of not the private key for this sub-key exists in the * keyring * - * @param boolean $hasPrivate true if the private key for this sub-key - * exists in the keyring and false if it does - * not. + * @param bool $hasPrivate True if the private key for this sub-key + * exists in the keyring and false if it does + * not. * - * @return Crypt_GPG_SubKey the current object, for fluent interface. + * @return Crypt_GPG_SubKey The current object, for fluent interface. */ public function setHasPrivate($hasPrivate) { @@ -579,9 +579,9 @@ public function setHasPrivate($hasPrivate) /** * Sets whether or not this sub-key is revoked * - * @param boolean $isRevoked whether or not this sub-key is revoked. + * @param bool $isRevoked Whether or not this sub-key is revoked. * - * @return Crypt_GPG_SubKey the current object, for fluent interface. + * @return Crypt_GPG_SubKey The current object, for fluent interface. */ public function setRevoked($isRevoked) { @@ -596,9 +596,9 @@ public function setRevoked($isRevoked) * {@link http://www.gnupg.org/download/ GPG distribution} for information * on how the sub-key string is parsed. * - * @param string $string the string containing the sub-key. + * @param string $string The string containing the sub-key. * - * @return Crypt_GPG_SubKey the sub-key object parsed from the string. + * @return Crypt_GPG_SubKey The sub-key object parsed from the string. */ public static function parse($string) { @@ -638,9 +638,9 @@ public static function parse($string) /** * Parses a date string as provided by GPG into a UNIX timestamp * - * @param string $string the date string. + * @param string $string The date string. * - * @return DateTime|null the date corresponding to the provided date string. + * @return DateTime|null The date corresponding to the provided date string. */ private static function _parseDate($string) { diff --git a/Crypt/GPG/UserId.php b/Crypt/GPG/UserId.php index 3019c27..a6de00f 100644 --- a/Crypt/GPG/UserId.php +++ b/Crypt/GPG/UserId.php @@ -70,14 +70,14 @@ class Crypt_GPG_UserId /** * Whether or not this user id is revoked * - * @var boolean + * @var bool */ private $_isRevoked = false; /** * Whether or not this user id is valid * - * @var boolean + * @var bool */ private $_isValid = true; @@ -90,8 +90,8 @@ class Crypt_GPG_UserId * - string name - the name field of the user id. * - string comment - the comment field of the user id. * - string email - the email field of the user id. - * - boolean valid - whether or not the user id is valid. - * - boolean revoked - whether or not the user id is revoked. + * - bool valid - whether or not the user id is valid. + * - bool revoked - whether or not the user id is revoked. * * @param Crypt_GPG_UserId|string|array|null $userId Either an existing user id object, * which is copied; a user id string, @@ -171,7 +171,7 @@ public function getEmail() /** * Gets whether or not this user id is revoked * - * @return boolean true if this user id is revoked and false if it is not. + * @return bool True if this user id is revoked and false if it is not. */ public function isRevoked() { @@ -181,7 +181,7 @@ public function isRevoked() /** * Gets whether or not this user id is valid * - * @return boolean true if this user id is valid and false if it is not. + * @return bool True if this user id is valid and false if it is not. */ public function isValid() { @@ -257,9 +257,9 @@ public function setEmail($email) /** * Sets whether or not this user id is revoked * - * @param boolean $isRevoked whether or not this user id is revoked. + * @param bool $isRevoked Whether or not this user id is revoked. * - * @return Crypt_GPG_UserId the current object, for fluent interface. + * @return Crypt_GPG_UserId The current object, for fluent interface. */ public function setRevoked($isRevoked) { @@ -270,9 +270,9 @@ public function setRevoked($isRevoked) /** * Sets whether or not this user id is valid * - * @param boolean $isValid whether or not this user id is valid. + * @param bool $isValid Whether or not this user id is valid. * - * @return Crypt_GPG_UserId the current object, for fluent interface. + * @return Crypt_GPG_UserId The current object, for fluent interface. */ public function setValid($isValid) { diff --git a/Crypt/GPGAbstract.php b/Crypt/GPGAbstract.php index efd6e42..35febc3 100644 --- a/Crypt/GPGAbstract.php +++ b/Crypt/GPGAbstract.php @@ -214,7 +214,7 @@ abstract class Crypt_GPGAbstract * - string digest-algo - Sets the message digest algorithm. * - string cipher-algo - Sets the symmetric cipher. * - string compress-algo - Sets the compression algorithm. - * - boolean strict - In strict mode clock problems on subkeys + * - bool strict - In strict mode clock problems on subkeys * and signatures are not ignored (--ignore-time-conflict * and --ignore-valid-from options). * - mixed debug - whether or not to use debug mode. diff --git a/composer.json b/composer.json index ae42e5b..df12d2d 100644 --- a/composer.json +++ b/composer.json @@ -47,6 +47,7 @@ "source": "https://github.com/pear/Crypt_GPG" }, "require-dev": { + "phpstan/phpstan": "^1.2", "phpunit/phpunit": "^9" }, "archive": { diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..fa8235c --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,11 @@ +parameters: + fileExtensions: + - php + + paths: + - Crypt + - tests + - tools + - scripts/crypt-gpg-pinentry + + level: 4 diff --git a/tests/KeyGeneratorTest.php b/tests/KeyGeneratorTest.php index 2d45bed..e1176b8 100644 --- a/tests/KeyGeneratorTest.php +++ b/tests/KeyGeneratorTest.php @@ -62,6 +62,8 @@ */ class KeyGeneratorTest extends Crypt_GPG_TestCase { + protected $generator; + protected function assertKeyEquals( Crypt_GPG_Key $key1, Crypt_GPG_Key $key2 diff --git a/tests/TestCase.php b/tests/TestCase.php index b809bf8..d5b7c8c 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -81,6 +81,7 @@ abstract class Crypt_GPG_TestCase extends PHPUnit\Framework\TestCase const TEMPDIR = 'temp-files'; const DATADIR = 'data-files'; + protected $config; protected $gpg; protected function getOptions()