Skip to content

Commit 86d6bb0

Browse files
committed
Psalm-fixes
1 parent 10338ad commit 86d6bb0

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

src/XMLSecEnc.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,16 @@ class XMLSecEnc
7070
/** @var string */
7171
public const XMLENCNS = 'http://www.w3.org/2001/04/xmlenc#';
7272

73-
/** @var null|\DOMDocument */
73+
/** @var \DOMDocument|null */
7474
private $encdoc = null;
7575

76-
/** @var null|\DOMNode */
76+
/** @var \DOMNode|null */
7777
private $rawNode = null;
7878

79-
/** @var null|string */
79+
/** @var string|null */
8080
public $type = null;
8181

82-
/** @var null|\DOMElement */
82+
/** @var \DOMElement|null */
8383
public $encKey = null;
8484

8585
/** @var array */
@@ -111,10 +111,6 @@ private function resetTemplate(): void
111111
*/
112112
public function addReference(string $name, DOMNode $node, string $type): void
113113
{
114-
if (!($node instanceof DOMNode)) {
115-
throw new Exception('$node is not of type DOMNode');
116-
}
117-
118114
$curencdoc = $this->encdoc;
119115
$this->resetTemplate();
120116
$encdoc = $this->encdoc;
@@ -143,24 +139,28 @@ public function setNode(DOMNode $node): void
143139
* @param bool $replace Whether the encrypted node should be replaced in the original tree. Default is true.
144140
* @throws \Exception
145141
*
146-
* @return \DOMElement The <xenc:EncryptedData>-element.
142+
* @return \DOMNode|false The <xenc:EncryptedData>-element.
147143
*/
148-
public function encryptNode(XMLSecurityKey $objKey, bool $replace = true): DOMElement
144+
public function encryptNode(XMLSecurityKey $objKey, bool $replace = true)
149145
{
150146
$data = '';
151147
if (empty($this->rawNode)) {
152148
throw new Exception('Node to encrypt has not been set');
153149
}
150+
154151
if (!($objKey instanceof XMLSecurityKey)) {
155152
throw new Exception('Invalid Key');
156153
}
154+
157155
$doc = $this->rawNode->ownerDocument;
158156
$xPath = new DOMXPath($this->encdoc);
159157
$objList = $xPath->query('/xenc:EncryptedData/xenc:CipherData/xenc:CipherValue');
158+
160159
$cipherValue = $objList->item(0);
161160
if ($cipherValue == null) {
162161
throw new Exception('Error locating CipherValue element within template');
163162
}
163+
164164
switch ($this->type) {
165165
case (self::ELEMENT):
166166
$data = $doc->saveXML($this->rawNode);
@@ -556,7 +556,7 @@ public static function staticLocateKeyInfo(XMLSecurityKey $objBaseKey = null, DO
556556
* @param \DOMNode|null $node
557557
* @return \RobRichards\XMLSecLibs\XMLSecurityKey|null
558558
*/
559-
public function locateKeyInfo(XMLSecurityKey $objBaseKey = null, DOMNode $node = null): XMLSecurityKey
559+
public function locateKeyInfo(XMLSecurityKey $objBaseKey = null, DOMNode $node = null): ?XMLSecurityKey
560560
{
561561
if (empty($node)) {
562562
$node = $this->rawNode;

src/XMLSecurityDSig.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ private function canonicalizeData(
305305

306306
if (
307307
is_null($arXPath)
308-
&& ($node instanceof DOMNode)
309308
&& ($node->ownerDocument !== null)
310309
&& $node->isSameNode($node->ownerDocument->documentElement)
311310
) {
@@ -432,9 +431,9 @@ public function validateDigest(DOMNode $refNode, string $data): bool
432431
* @param \DOMNode $refNode
433432
* @param \DOMNode $objData
434433
* @param bool $includeCommentNodes
435-
* @return string
434+
* @return \DOMNode|string
436435
*/
437-
public function processTransforms(DOMNode $refNode, DOMNode $objData, bool $includeCommentNodes = true): string
436+
public function processTransforms(DOMNode $refNode, DOMNode $objData, bool $includeCommentNodes = true)
438437
{
439438
$data = $objData;
440439
$xpath = new DOMXPath($refNode->ownerDocument);
@@ -822,7 +821,7 @@ public function addReferenceList(
822821

823822

824823
/**
825-
* @param \DOMElement|string $data
824+
* @param \DOMElement $data
826825
* @param string|null $mimetype
827826
* @param string|null $encoding
828827
* @return \DOMElement

src/XMLSecurityKey.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -842,9 +842,9 @@ public function serializeKey($parent): void
842842
* Will return the X509 certificate in PEM-format if this key represents
843843
* an X509 certificate.
844844
*
845-
* @return string The X509 certificate or null if this key doesn't represent an X509-certificate.
845+
* @return string|null The X509 certificate or null if this key doesn't represent an X509-certificate.
846846
*/
847-
public function getX509Certificate(): string
847+
public function getX509Certificate(): ?string
848848
{
849849
return $this->x509Certificate;
850850
}
@@ -857,9 +857,9 @@ public function getX509Certificate(): string
857857
* The thumbprint as a lowercase 40-character hexadecimal number, or null
858858
* if this isn't a X509 certificate.
859859
*
860-
* @return string Lowercase 40-character hexadecimal number of thumbprint
860+
* @return string|null Lowercase 40-character hexadecimal number of thumbprint
861861
*/
862-
public function getX509Thumbprint(): string
862+
public function getX509Thumbprint(): ?string
863863
{
864864
return $this->X509Thumbprint;
865865
}

0 commit comments

Comments
 (0)