Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F6134067
ChildElementMatcher.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
ChildElementMatcher.php
View Options
<?php
namespace
WMDE\HamcrestHtml
;
use
DOMDocument
;
use
DOMNode
;
use
Hamcrest\Description
;
use
Hamcrest\Matcher
;
use
Hamcrest\TypeSafeDiagnosingMatcher
;
class
ChildElementMatcher
extends
TypeSafeDiagnosingMatcher
{
/**
* @var Matcher|null
*/
private
$matcher
;
public
static
function
havingChild
(
?
Matcher
$elementMatcher
=
null
)
{
return
new
static
(
$elementMatcher
);
}
public
function
__construct
(
?
Matcher
$matcher
=
null
)
{
parent
::
__construct
(
DOMNode
::
class
);
$this
->
matcher
=
$matcher
;
}
public
function
describeTo
(
Description
$description
)
{
$description
->
appendText
(
'having child '
);
if
(
$this
->
matcher
)
{
$description
->
appendDescriptionOf
(
$this
->
matcher
);
}
}
/**
* @param DOMDocument|DOMNode $item
* @param Description $mismatchDescription
*
* @return bool
*/
protected
function
matchesSafelyWithDiagnosticDescription
(
$item
,
Description
$mismatchDescription
)
{
if
(
$item
instanceof
DOMDocument
)
{
$directChildren
=
$item
->
documentElement
->
childNodes
->
item
(
0
)->
childNodes
;
}
else
{
$directChildren
=
$item
->
childNodes
;
}
if
(
$directChildren
->
length
===
0
)
{
$mismatchDescription
->
appendText
(
'having no children'
);
return
false
;
}
if
(
!
$this
->
matcher
)
{
return
$directChildren
->
length
>
0
;
}
foreach
(
new
XmlNodeRecursiveIterator
(
$directChildren
)
as
$child
)
{
if
(
$this
->
matcher
->
matches
(
$child
)
)
{
return
true
;
}
}
$mismatchDescription
->
appendText
(
'having no children '
)->
appendDescriptionOf
(
$this
->
matcher
);
return
false
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Oct 7 2026, 13:34 (6 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
68/2d/e0cc9b8272d407e173293c6cc4e3
Default Alt Text
ChildElementMatcher.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment