Skip to content

Commit

Permalink
Fix linting error
Browse files Browse the repository at this point in the history
  • Loading branch information
Prashant-bd committed Nov 16, 2023
1 parent da0be56 commit 56005ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
6 changes: 4 additions & 2 deletions embargo.module
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use Drupal\Core\Database\Query\AlterableInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\embargo\EmbargoStorage;
use Drupal\node\NodeInterface;

/**
* Implements hook_entity_type_alter().
Expand Down Expand Up @@ -109,7 +110,7 @@ function embargo_embargo_update(EntityInterface $entity) {
$node_reference = $entity->get('embargoed_node')->entity;

// Check if the referenced entity is a node.
if ($node_reference instanceof \Drupal\node\NodeInterface) {
if ($node_reference instanceof NodeInterface) {

// Load the node using the entity type manager.
$entityTypeManager = \Drupal::entityTypeManager();
Expand All @@ -120,7 +121,8 @@ function embargo_embargo_update(EntityInterface $entity) {
\Drupal::getContainer()->get('search_api.entity_datasource.tracking_manager')
->entityUpdate($node);

// Attempt to track all items as changed that indexed updated data indirectly.
// Attempt to track all items as changed that indexed
// updated data indirectly.
\Drupal::getContainer()->get('search_api.tracking_helper')
->trackReferencedEntityUpdate($node);
}
Expand Down
19 changes: 10 additions & 9 deletions src/Plugin/search_api/processor/EmbargoIpRestriction.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* }
* )
*/
class EmbargoIpRestriction extends ProcessorPluginBase implements ContainerFactoryPluginInterface{
class EmbargoIpRestriction extends ProcessorPluginBase implements ContainerFactoryPluginInterface {

/**
* The request stack.
Expand Down Expand Up @@ -66,15 +66,15 @@ class EmbargoIpRestriction extends ProcessorPluginBase implements ContainerFacto
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
* The request stack.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The Entity Type Manager.
* @param \Drupal\Core\Session\AccountProxyInterface $currentUser
* The Account Proxy.
*
* @throws \Drupal\facets\Exception\InvalidProcessorException
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, RequestStack $request_stack, EntityTypeManagerInterface $entity_type_manager, AccountProxyInterface $currentUser) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, RequestStack $request_stack, EntityTypeManagerInterface $entity_type_manager, AccountProxyInterface $currentUser) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->requestStack = $request_stack;
$this->entityTypeManager = $entity_type_manager;
Expand Down Expand Up @@ -181,7 +181,8 @@ public function preprocessSearchQuery(QueryInterface $query) {
// Convert User IP into CIDR format query matching.
$currentUserIpCidr = $this->ipToCidr($currentUserIp);

// Add the condition to check if the user's IP is in the list using CIDR notation
// Add the condition to check if the user's IP
// is in the list using CIDR notation
$conditions->addCondition('embargo_ip', $currentUserIpCidr);
$conditions->addCondition('embargo_ip', NULL);
}
Expand All @@ -205,22 +206,22 @@ public function preprocessSearchQuery(QueryInterface $query) {
* @return string
* The CIDR notation representation of the IP address.
*/
function ipToCidr($ip, $subnetMask = 24) {
public function ipToCidr($ip, $subnetMask = 24) {
// Check if the IP is IPv6.
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
// For simplicity, let's assume a default subnet mask of 128 for IPv6
// For simplicity, let's assume a default subnet mask of 128 for IPv6.
return $ip . '/128';
}

$ipParts = explode('.', $ip);

// Ensure subnet mask is within valid range (0-32)
// Ensure subnet mask is within valid range (0-32).
$subnetMask = max(0, min(32, $subnetMask));

// Calculate the network portion of the IP based on the subnet mask
// Calculate the network portion of the IP based on the subnet mask.
$network = implode('.', array_slice($ipParts, 0, floor($subnetMask / 8)));

// Build the CIDR notation
// Build the CIDR notation.
$cidr = $network . '.0/' . $subnetMask;

return $cidr;
Expand Down

0 comments on commit 56005ad

Please sign in to comment.