Skip to content

Commit

Permalink
Psalm-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed May 11, 2020
1 parent 10338ad commit 86d6bb0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
22 changes: 11 additions & 11 deletions src/XMLSecEnc.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ class XMLSecEnc
/** @var string */
public const XMLENCNS = 'http://www.w3.org/2001/04/xmlenc#';

/** @var null|\DOMDocument */
/** @var \DOMDocument|null */
private $encdoc = null;

/** @var null|\DOMNode */
/** @var \DOMNode|null */
private $rawNode = null;

/** @var null|string */
/** @var string|null */
public $type = null;

/** @var null|\DOMElement */
/** @var \DOMElement|null */
public $encKey = null;

/** @var array */
Expand Down Expand Up @@ -111,10 +111,6 @@ private function resetTemplate(): void
*/
public function addReference(string $name, DOMNode $node, string $type): void
{
if (!($node instanceof DOMNode)) {
throw new Exception('$node is not of type DOMNode');
}

$curencdoc = $this->encdoc;
$this->resetTemplate();
$encdoc = $this->encdoc;
Expand Down Expand Up @@ -143,24 +139,28 @@ public function setNode(DOMNode $node): void
* @param bool $replace Whether the encrypted node should be replaced in the original tree. Default is true.
* @throws \Exception
*
* @return \DOMElement The <xenc:EncryptedData>-element.
* @return \DOMNode|false The <xenc:EncryptedData>-element.
*/
public function encryptNode(XMLSecurityKey $objKey, bool $replace = true): DOMElement
public function encryptNode(XMLSecurityKey $objKey, bool $replace = true)
{
$data = '';
if (empty($this->rawNode)) {
throw new Exception('Node to encrypt has not been set');
}

if (!($objKey instanceof XMLSecurityKey)) {
throw new Exception('Invalid Key');
}

$doc = $this->rawNode->ownerDocument;
$xPath = new DOMXPath($this->encdoc);
$objList = $xPath->query('/xenc:EncryptedData/xenc:CipherData/xenc:CipherValue');

$cipherValue = $objList->item(0);
if ($cipherValue == null) {
throw new Exception('Error locating CipherValue element within template');
}

switch ($this->type) {
case (self::ELEMENT):
$data = $doc->saveXML($this->rawNode);
Expand Down Expand Up @@ -556,7 +556,7 @@ public static function staticLocateKeyInfo(XMLSecurityKey $objBaseKey = null, DO
* @param \DOMNode|null $node
* @return \RobRichards\XMLSecLibs\XMLSecurityKey|null
*/
public function locateKeyInfo(XMLSecurityKey $objBaseKey = null, DOMNode $node = null): XMLSecurityKey
public function locateKeyInfo(XMLSecurityKey $objBaseKey = null, DOMNode $node = null): ?XMLSecurityKey
{
if (empty($node)) {
$node = $this->rawNode;
Expand Down
7 changes: 3 additions & 4 deletions src/XMLSecurityDSig.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ private function canonicalizeData(

if (
is_null($arXPath)
&& ($node instanceof DOMNode)
&& ($node->ownerDocument !== null)
&& $node->isSameNode($node->ownerDocument->documentElement)
) {
Expand Down Expand Up @@ -432,9 +431,9 @@ public function validateDigest(DOMNode $refNode, string $data): bool
* @param \DOMNode $refNode
* @param \DOMNode $objData
* @param bool $includeCommentNodes
* @return string
* @return \DOMNode|string
*/
public function processTransforms(DOMNode $refNode, DOMNode $objData, bool $includeCommentNodes = true): string
public function processTransforms(DOMNode $refNode, DOMNode $objData, bool $includeCommentNodes = true)
{
$data = $objData;
$xpath = new DOMXPath($refNode->ownerDocument);
Expand Down Expand Up @@ -822,7 +821,7 @@ public function addReferenceList(


/**
* @param \DOMElement|string $data
* @param \DOMElement $data
* @param string|null $mimetype
* @param string|null $encoding
* @return \DOMElement
Expand Down
8 changes: 4 additions & 4 deletions src/XMLSecurityKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -842,9 +842,9 @@ public function serializeKey($parent): void
* Will return the X509 certificate in PEM-format if this key represents
* an X509 certificate.
*
* @return string The X509 certificate or null if this key doesn't represent an X509-certificate.
* @return string|null The X509 certificate or null if this key doesn't represent an X509-certificate.
*/
public function getX509Certificate(): string
public function getX509Certificate(): ?string
{
return $this->x509Certificate;
}
Expand All @@ -857,9 +857,9 @@ public function getX509Certificate(): string
* The thumbprint as a lowercase 40-character hexadecimal number, or null
* if this isn't a X509 certificate.
*
* @return string Lowercase 40-character hexadecimal number of thumbprint
* @return string|null Lowercase 40-character hexadecimal number of thumbprint
*/
public function getX509Thumbprint(): string
public function getX509Thumbprint(): ?string
{
return $this->X509Thumbprint;
}
Expand Down

0 comments on commit 86d6bb0

Please sign in to comment.