Skip to content

Commit

Permalink
Fix various code and doc issues (add phpstan setup)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpl committed Mar 23, 2024
1 parent 5e582a3 commit d918602
Show file tree
Hide file tree
Showing 19 changed files with 356 additions and 340 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ tools/ export-ignore
.gitignore export-ignore
package.php export-ignore
package.xml export-ignore
phpstan.neon export-ignore
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ vendor
tests/config.php
tests/debug.log
tests/test-keychain/
tests/.phpunit.result.cache
187 changes: 93 additions & 94 deletions Crypt/GPG.php

Large diffs are not rendered by default.

47 changes: 23 additions & 24 deletions Crypt/GPG/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
*/
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -357,7 +357,7 @@ class Crypt_GPG_Engine
/**
* A status/error handler
*
* @var Crypt_GPG_ProcessHanler
* @var Crypt_GPG_ProcessHandler|null
*/
private $_processHandler = null;

Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.
*
Expand All @@ -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.
*
Expand Down Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand Down Expand Up @@ -908,7 +906,7 @@ public function setOptions(array $options)
* Use the <kbd>debug</kbd> 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()
Expand Down Expand Up @@ -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'];
}

Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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()
{
Expand All @@ -1943,6 +1940,8 @@ private function _getPinEntry()
return $path . $ds . 'crypt-gpg-pinentry';
}
}

return null;
}

/**
Expand Down
68 changes: 34 additions & 34 deletions Crypt/GPG/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '')
{
Expand Down Expand Up @@ -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()
*/
Expand Down Expand Up @@ -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 = '')
{
Expand Down Expand Up @@ -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= '')
{
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
*/
Expand Down Expand Up @@ -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,
Expand All @@ -454,7 +454,7 @@ public function __construct(
/**
* Gets the key algorithm
*
* @return integer the key algorithm.
* @return int The key algorithm.
*/
public function getAlgorithm()
{
Expand All @@ -464,7 +464,7 @@ public function getAlgorithm()
/**
* Gets the key size
*
* @return integer the key size.
* @return int The key size.
*/
public function getSize()
{
Expand All @@ -474,7 +474,7 @@ public function getSize()
/**
* Gets the key usage
*
* @return integer the key usage.
* @return int The key usage.
*/
public function getUsage()
{
Expand Down
Loading

0 comments on commit d918602

Please sign in to comment.