Skip to content

Instantly share code, notes, and snippets.

@tiffany-taylor
Created September 1, 2021 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiffany-taylor/7f99fe2ca348c23e8f90a5e50170e56e to your computer and use it in GitHub Desktop.
Save tiffany-taylor/7f99fe2ca348c23e8f90a5e50170e56e to your computer and use it in GitHub Desktop.
<?php
private function blahblahblah(\DOMXPath $xpath)
{
$node = $xpath->query('/some/valid/xpath/query')->item(0);
if ($node === null) {
// log message stating node wasn't found
return '';
}
$text = $node->textContent;
if ($text === '') {
// log message stating node was found, but it was empty
return '';
}
// proceed with code that processes $text
}
// vs.
private function asfasdfasdf(\DOMXPath $xpath)
{
$node = $xpath->query('/some/valid/xpath/query')->item(0);
if ($node === null || empty($node->textContent)) {
// log message that node wasn't found or it was empty
return '';
}
$text = $node->textContent;
// proceed with code that processes $text
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment