Skip to content

Commit

Permalink
Merge pull request #2042 from GSA/2039-phpstan-fixes
Browse files Browse the repository at this point in the history
PXBF-2039-phpstan-fixes
  • Loading branch information
scottqueen-bixal authored Feb 6, 2025
2 parents 440da02 + 05dd7f2 commit 318ab71
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\File\FileExists;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\File\FileUrlGeneratorInterface;
use Drupal\file\FileRepositoryInterface;
Expand Down Expand Up @@ -67,9 +68,9 @@ class LifeEventController extends ControllerBase {
/**
* The display data control variable.
*
* @var string
* @var bool
*/
protected $displayData;
protected bool $displayData;

/**
* The benefit finder content mode.
Expand All @@ -85,11 +86,11 @@ class LifeEventController extends ControllerBase {
* The entity type manager.
* @param \Drupal\Core\File\FileSystemInterface $file_system
* The file system service.
* @param \Drupal\file\FileRepositoryInterface|null $file_repository
* @param \Drupal\file\FileRepositoryInterface $file_repository
* The file repository.
* @param \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator
* The file URL generator.
* @param \Drupal\Core\Database\Connection $connection
* @param \Drupal\Core\Database\Connection $database
* The database connection.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
Expand Down Expand Up @@ -161,7 +162,7 @@ public function saveJsonData($id) {

// Write JSON data file.
$filename = "$directory/$id.json";
$this->fileRepository->writeData($data, $filename, FileSystemInterface::EXISTS_REPLACE);
$this->fileRepository->writeData($data, $filename, FileExists::Replace);

$fileUrlString = $this->fileUrlGenerator->generate($filename)->toString();

Expand Down Expand Up @@ -311,9 +312,7 @@ public function getData($id) {

// Build benefits.
foreach ($benefit_nodes as $benefit_node) {
if (!empty($benefit_node)) {
$benefits[]["benefit"] = $this->buildBenefit($benefit_node);
}
$benefits[]["benefit"] = $this->buildBenefit($benefit_node);
}

// Encode JSON data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ class CheckDataController extends ControllerBase {
* The entity type manager.
* @param \Drupal\Core\File\FileSystemInterface $file_system
* The file system service.
* @param \Drupal\file\FileRepositoryInterface|null $file_repository
* @param \Drupal\file\FileRepositoryInterface $file_repository
* The file repository.
* @param \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator
* The file URL generator.
* @param \Drupal\Core\Database\Connection $connection
* @param \Drupal\Core\Database\Connection $database
* The database connection.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
*/

use Drupal\Core\Database\Database;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\node\NodeInterface;
use Drupal\node\Entity\Node;

/**
Expand All @@ -28,7 +30,7 @@ function usagov_benefit_finder_content_form_alter(&$form, &$form_state, $form_id
$form['field_b_eligibility']['widget'][$i]['subform']['field_b_criteria_key']['widget']['#options'];
}
$i++;
} while ($i > 0);
} while (TRUE);
}
}

Expand Down Expand Up @@ -482,8 +484,16 @@ function usagov_benefit_finder_content_form_node_bears_life_event_form_edit_form
function _usagov_benefit_finder_content_check_life_event_form_criteria_depth(array &$form, FormStateInterface $form_state) {
$error_flag = FALSE;
$criteria_depths = [];
$life_event_form_node = NULL;

$form_object = $form_state->getFormObject();
if ($form_object instanceof EntityForm) {
$entity = $form_object->getEntity();
if ($entity instanceof NodeInterface) {
$life_event_form_node = $entity;
}
}

$life_event_form_node = $form_state->getFormObject()->getEntity();
$sections = $life_event_form_node->get('field_b_sections_elg_criteria')->referencedEntities();

foreach ($sections as $section) {
Expand Down
19 changes: 11 additions & 8 deletions usagov_benefit_finder/src/Traits/BenefitFinderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ trait BenefitFinderTrait {
* The Life Event ID.
* @param string $mode
* The benefit finder content mode.
* @return NodeInterface
* @return NodeInterface|NULL
* The life event node.
*/
public function getLifeEventById($id, $mode) {
Expand All @@ -49,7 +49,7 @@ public function getLifeEventById($id, $mode) {
* The Life Event form ID.
* @param string $mode
* The benefit finder content mode.
* @return NodeInterface
* @return NodeInterface|NULL
* The life event form node.
*/
public function getLifeEventFormById($id, $mode) {
Expand All @@ -73,7 +73,7 @@ public function getLifeEventFormById($id, $mode) {
* The life event form node ID.
* @param string $mode
* The benefit finder content mode.
* @return NodeInterface[]
* @return NodeInterface[]|NULL
* The benefit nodes.
*/
public function getBenefitsByLifeEventForm($nid, $mode) {
Expand All @@ -99,7 +99,7 @@ public function getBenefitsByLifeEventForm($nid, $mode) {
* The agency node ID.
* @param string $mode
* The benefit finder content mode.
* @return NodeInterface
* @return NodeInterface|NULL
* The agency node.
*/
public function getAgency($nid, $mode) {
Expand All @@ -113,7 +113,7 @@ public function getAgency($nid, $mode) {
* The criteria node ID.
* @param string $mode
* The benefit finder content mode.
* @return NodeInterface
* @return NodeInterface|NULL
* The criteria node.
*/
public function getCriteria($nid, $mode) {
Expand All @@ -127,7 +127,7 @@ public function getCriteria($nid, $mode) {
* The benefit node ID.
* @param string $mode
* The benefit finder content mode.
* @return NodeInterface
* @return NodeInterface|NULL
* The benefit node.
*/
public function getBenefit($nid, $mode) {
Expand All @@ -141,7 +141,7 @@ public function getBenefit($nid, $mode) {
* The life event form node ID.
* @param string $mode
* The benefit finder content mode.
* @return NodeInterface
* @return NodeInterface|NULL
* The life event form node.
*/
public function getLifeEventForm($nid, $mode) {
Expand All @@ -155,10 +155,13 @@ public function getLifeEventForm($nid, $mode) {
* The node ID.
* @param string $mode
* The benefit finder content mode.
* @return EntityInterface|NodeInterface
* @return NodeInterface|NULL
* The node revision entity.
*/
public function getNode($nid, $mode) {
/** @var \Drupal\Core\Entity\Query\QueryInterface|null $query */
$query = NULL;

$node = Node::load($nid);

if (!$node) {
Expand Down

0 comments on commit 318ab71

Please sign in to comment.