Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PHPCS. #509

Merged
merged 7 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Drupal coding standards

on: pull_request

jobs:
phpcs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@verbose
with:
php-version: 8.3
coverage: none
tools: composer:v2, cs2pr, dealerdirect/phpcodesniffer-composer-installer:*, drupal/coder
- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Detect coding standard violations
run: phpcs -q --report=checkstyle | cs2pr
2 changes: 1 addition & 1 deletion civicrm_entity.module
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ function civicrm_entity_module_implements_alter(&$implementations, $hook) {
* @return array
* The array of field options.
*/
function civicrm_entity_pseudoconstant_options(FieldStorageDefinitionInterface $definition, FieldableEntityInterface $entity = NULL, &$cacheable = NULL) {
function civicrm_entity_pseudoconstant_options(FieldStorageDefinitionInterface $definition, ?FieldableEntityInterface $entity = NULL, &$cacheable = NULL) {
/** @var \Drupal\civicrm_entity\CiviCrmApiInterface $civicrm_api */
$civicrm_api = \Drupal::service('civicrm_entity.api');
$entity_type = \Drupal::entityTypeManager()->getDefinition($definition->getTargetEntityTypeId());
Expand Down
11 changes: 11 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="civicrm_entity">
<description>PHP CodeSniffer configuration for CiviCRM entity.</description>
<file>.</file>
<arg name="extensions" value="php,module,inc,install,test,profile,theme,info,yml"/>

<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/node_modules/*</exclude-pattern>

<rule ref="Drupal"/>
</ruleset>
10 changes: 5 additions & 5 deletions src/CiviEntityStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
use Drupal\field\FieldStorageConfigInterface;
use Psr\Log\LoggerInterface;

/**
* Defines entity class for external CiviCRM entities.
Expand Down Expand Up @@ -78,7 +77,7 @@ private function getConfigFactory() {
return $this->configFactory;
}

/**
/**
* Gets the config factory.
*
* @return \Psr\Log\LoggerInterface
Expand Down Expand Up @@ -169,7 +168,7 @@ protected function doSave($id, EntityInterface $entity) {
*
* @throws \Drupal\Core\Entity\Sql\SqlContentEntityStorageException
*/
protected function doLoadMultiple(array $ids = NULL) {
protected function doLoadMultiple(?array $ids = NULL) {
$entities = [];
if ($ids === NULL) {
$civicrm_entity = $this->getCiviCrmApi()->get($this->entityType->get('civicrm_entity'));
Expand Down Expand Up @@ -463,7 +462,8 @@ protected function initFieldValues(ContentEntityInterface $entity, array $values

// Handle special cases for field definitions.
foreach ($field_definitions as $definition) {
if (($field_metadata = $definition->getSetting('civicrm_entity_field_metadata')) && isset($field_metadata['custom_group_id']) && in_array($field_metadata['data_type'],['Float', 'Money'])) {
$data_types = ['Float', 'Money'];
if (($field_metadata = $definition->getSetting('civicrm_entity_field_metadata')) && isset($field_metadata['custom_group_id']) && in_array($field_metadata['data_type'], $data_types)) {
$items = $entity->get($definition->getName());
$item_values = $items->getValue();
if (!empty($item_values)) {
Expand Down Expand Up @@ -502,7 +502,7 @@ protected function initFieldValues(ContentEntityInterface $entity, array $values
/**
* {@inheritdoc}
*/
public function getTableMapping(array $storage_definitions = NULL) {
public function getTableMapping(?array $storage_definitions = NULL) {
$table_mapping = $this->tableMapping;

if ($table_mapping) {
Expand Down
6 changes: 4 additions & 2 deletions src/CivicrmEntityViewsData.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CivicrmEntityViewsData extends EntityViewsData {
/**
* {@inheritdoc}
*/
public function __construct(EntityTypeInterface $entity_type, SqlEntityStorageInterface $storage_controller, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, TranslationInterface $translation_manager, EntityFieldManagerInterface $entity_field_manager = NULL, CiviCrmApiInterface $civicrm_api) {
public function __construct(EntityTypeInterface $entity_type, SqlEntityStorageInterface $storage_controller, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, TranslationInterface $translation_manager, EntityFieldManagerInterface $entity_field_manager, CiviCrmApiInterface $civicrm_api) {
parent::__construct($entity_type, $storage_controller, $entity_type_manager, $module_handler, $translation_manager, $entity_field_manager);
$this->civicrmApi = $civicrm_api;
$this->civicrmApi->civicrmInitialize();
Expand Down Expand Up @@ -495,13 +495,15 @@ protected function processViewsDataForSpecialFields(array &$views_field, $base_t
}

break;

case 'civicrm_website':
if (isset($views_field['civicrm_contact']['reverse__civicrm_website__contact_id']['relationship'])) {
$views_field['civicrm_contact']['reverse__civicrm_website__contact_id']['relationship']['id'] = 'civicrm_entity_reverse_website_type';
$views_field['civicrm_contact']['reverse__civicrm_website__contact_id']['relationship']['label'] = $this->t('Website');
}

break;

case 'civicrm_address':
if (isset($views_field['civicrm_contact']['reverse__civicrm_address__contact_id']['relationship'])) {
$views_field['civicrm_contact']['reverse__civicrm_address__contact_id']['relationship']['id'] = 'civicrm_entity_reverse_location';
Expand Down
3 changes: 3 additions & 0 deletions src/Entity/CivicrmEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ public function civicrmApiNormalize() {
return $params;
}

/**
* Get raw value.
*/
public function getRawValue($field) {
return $this->values[$field] ?? '';
}
Expand Down
1 change: 0 additions & 1 deletion src/Entity/Sql/CivicrmEntityStorageSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public function requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterfac
* {@inheritdoc}
*/
public function onFieldableEntityTypeCreate(EntityTypeInterface $entity_type, array $field_storage_definitions) {
return;
}

}
2 changes: 1 addition & 1 deletion src/Plugin/Action/CivicrmContactAddToGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
/**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
public function access($object, ?AccountInterface $account = NULL, $return_as_object = FALSE) {
return $object->access('update', $account, $return_as_object);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ContactReferenceFormatter extends EntityReferenceLabelFormatter {
protected function checkAccess(EntityInterface $entity) {
$permissions = [
'view all contacts',
'access all custom data'
'access all custom data',
];
$account = User::load(\Drupal::currentUser()->id());
return AccessResult::allowedIfHasPermissions($account, $permissions, 'OR');
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/Field/FieldFormatter/CustomMultiValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
field_types: [
"list_integer",
"list_float",
"list_string"
"list_string",
]
)]
class CustomMultiValue extends OptionsDefaultFormatter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
id: "civicrm_entity_state_province_iso",
label: new TranslatableMarkup("State province ISO"),
field_types: [
"list_integer"
"list_integer",
]
)]
class StateProvinceIsoFormatter extends FormatterBase {
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/Field/FieldWidget/TextareaWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
id: "civicrm_entity_textarea",
label: new TranslatableMarkup("Text area (multiple rows, default CiviCRM format 1)"),
field_types: [
"text_long"
"text_long",
]
)]
class TextareaWidget extends CoreTextareaWidget {
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/RulesAction/LoadLinkedUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"user_fetched" => new ContextDefinition(
data_type: "entity:user",
label: new TranslatableMarkup("Fetched user"),
)
),
]
)]
class LoadLinkedUser extends RulesActionBase implements ContainerFactoryPluginInterface {
Expand Down
12 changes: 6 additions & 6 deletions src/Plugin/RulesAction/UserCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,42 +69,42 @@
label: new TranslatableMarkup("CiviCRM contact ID"),
description: new TranslatableMarkup("The CiviCRM contact ID."),
required: TRUE
),
),
"is_active" => new ContextDefinition(
data_type: "boolean",
label: new TranslatableMarkup("Activate account"),
description: new TranslatableMarkup("Set to TRUE to activate account. Leave empty to NOT activate the account. Defaults to TRUE."),
assignment_restriction: "input",
default_value: "TRUE",
required: FALSE
),
),
"notify" => new ContextDefinition(
data_type: "boolean",
label: new TranslatableMarkup("Send account notification email"),
description: new TranslatableMarkup("Set to TRUE to send a notification email. Leave empty to not send an account notification email."),
assignment_restriction: "input",
default_value: FALSE,
required: FALSE
),
),
"signin" => new ContextDefinition(
data_type: "boolean",
label: new TranslatableMarkup("Instant signin"),
description: new TranslatableMarkup("Set to TRUE to automatically log in the user. Leave empty to not automatically log in the user."),
assignment_restriction: "input",
default_value: FALSE,
required: FALSE
),
),
"format" => new ContextDefinition(
data_type: "string",
label: new TranslatableMarkup("Format"),
description: new TranslatableMarkup("Format of the username.")
)
),
],
provides: [
"user_fetched" => new ContextDefinition(
data_type: "entity:user",
label: new TranslatableMarkup("Created Drupal user"),
)
),
]
)]
class UserCreate extends RulesActionBase implements ContainerFactoryPluginInterface {
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/TypedDataFilter/FirstDotLastFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function filtersTo(DataDefinitionInterface $definition, array $arguments)
/**
* {@inheritdoc}
*/
public function filter(DataDefinitionInterface $definition, $value, array $arguments, BubbleableMetadata $bubbleable_metadata = NULL) {
public function filter(DataDefinitionInterface $definition, $value, array $arguments, ?BubbleableMetadata $bubbleable_metadata = NULL) {
$login = str_replace(' ', '', strtolower($value->get('first_name')->getString())) . '.' . strtolower($value->get('last_name')->getString());

return filter_var($login, FILTER_SANITIZE_EMAIL);
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/TypedDataFilter/FirstLastFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function filtersTo(DataDefinitionInterface $definition, array $arguments)
/**
* {@inheritdoc}
*/
public function filter(DataDefinitionInterface $definition, $value, array $arguments, BubbleableMetadata $bubbleable_metadata = NULL) {
public function filter(DataDefinitionInterface $definition, $value, array $arguments, ?BubbleableMetadata $bubbleable_metadata = NULL) {
$login = str_replace(' ', '', ucfirst(strtolower($value->get('first_name')->getString()))) . ucfirst(strtolower($value->get('last_name')->getString()));

return filter_var($login, FILTER_SANITIZE_EMAIL);
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/TypedDataFilter/InitialDotLastFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function filtersTo(DataDefinitionInterface $definition, array $arguments)
/**
* {@inheritdoc}
*/
public function filter(DataDefinitionInterface $definition, $value, array $arguments, BubbleableMetadata $bubbleable_metadata = NULL) {
public function filter(DataDefinitionInterface $definition, $value, array $arguments, ?BubbleableMetadata $bubbleable_metadata = NULL) {
$c = preg_match_all("/(?<=\b)[a-z]/i", ($value->get('first_name')->getString()), $m);
if ($c > 0) {
$login = strtolower(implode('', $m[0])) . '.' . strtolower($value->get('last_name')->getString());
Expand Down
3 changes: 3 additions & 0 deletions src/Plugin/search_api/datasource/CivicrmEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use Drupal\search_api\Plugin\search_api\datasource\ContentEntity;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Datasource for CiviCRM entity.
*/
class CivicrmEntity extends ContentEntity {

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/views/field/ActivityAttachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi
/**
* {@inheritdoc}
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) {
parent::init($view, $display, $options);
$this->civicrmApi->civicrmInitialize();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Plugin/views/field/CustomEntityField.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CustomEntityField extends EntityField {
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, FormatterPluginManager $formatter_plugin_manager, FieldTypePluginManagerInterface $field_type_plugin_manager, LanguageManagerInterface $language_manager, RendererInterface $renderer, EntityRepositoryInterface $entity_repository = NULL, EntityFieldManagerInterface $entity_field_manager = NULL, EntityTypeBundleInfoInterface $entity_type_bundle_info, CiviCrmApiInterface $civicrm_api) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, FormatterPluginManager $formatter_plugin_manager, FieldTypePluginManagerInterface $field_type_plugin_manager, LanguageManagerInterface $language_manager, RendererInterface $renderer, ?EntityRepositoryInterface $entity_repository = NULL, ?EntityFieldManagerInterface $entity_field_manager = NULL, EntityTypeBundleInfoInterface $entity_type_bundle_info, CiviCrmApiInterface $civicrm_api) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager, $formatter_plugin_manager, $field_type_plugin_manager, $language_manager, $renderer, $entity_repository, $entity_field_manager, $entity_type_bundle_info);
$this->civicrmApi = $civicrm_api;
}
Expand Down Expand Up @@ -93,7 +93,7 @@ public static function create(ContainerInterface $container, array $configuratio
/**
* {@inheritdoc}
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) {
$field_definition = $this->getFieldDefinition();

if ($settings = $field_definition->getSetting('civicrm_entity_field_metadata')) {
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/views/field/CustomFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi
/**
* {@inheritdoc}
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) {
parent::init($view, $display, $options);
$this->civicrmApi->civicrmInitialize();
$this->additional_fields['entity_id'] = 'entity_id';
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/views/filter/ContactReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function acceptExposedInput($input) {
/**
* {@inheritdoc}
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) {
parent::init($view, $display, $options);
$this->civicrmApi->civicrmInitialize();
}
Expand Down
8 changes: 7 additions & 1 deletion src/Plugin/views/filter/InOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi
/**
* {@inheritdoc}
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) {
parent::init($view, $display, $options);
$this->civicrmApi->civicrmInitialize();
}
Expand Down Expand Up @@ -140,6 +140,9 @@ protected function opSimple() {
}
}

/**
* {@inheritdoc}
*/
public function operators() {
$operators = parent::operators();
if (!empty($this->definition['allow empty'])) {
Expand All @@ -161,6 +164,9 @@ public function operators() {
return $operators;
}

/**
* Operation for empty string.
*/
protected function opEmptyString() {
$this->ensureMyTable();
$field = "$this->tableAlias.$this->realField";
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/views/filter/Proximity.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static function create(ContainerInterface $container, array $configuratio
/**
* {@inheritdoc}
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) {
parent::init($view, $display, $options);
$this->civicrmApi->civicrmInitialize();
\CRM_Contact_BAO_ProximityQuery::initialize();
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/views/query/CivicrmSql.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function create(ContainerInterface $container, array $configuratio
/**
* {@inheritdoc}
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) {
// Ensure that Drupal is aware of the CiviCRM database connection.
// This should be added into the settings.php, but we provide a backwards
// compatibility layer here.
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/views/relationship/CiviCrmActivityContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
/**
* {@inheritdoc}
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) {
parent::init($view, $display, $options);

$this->definition['extra'] = [];
Expand Down
1 change: 0 additions & 1 deletion src/Plugin/views/relationship/CiviCrmContactUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Drupal\Core\Utility\Error;
use Drupal\views\Attribute\ViewsRelationship;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Psr\Log\LoggerInterface;

/**
* Relationship for referencing civicrm_contact and user.
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/views/relationship/EntityReverseLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static function create(ContainerInterface $container, array $configuratio
/**
* {@inheritdoc}
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) {
parent::init($view, $display, $options);

$this->civicrmApi->civicrmInitialize();
Expand Down
Loading
Loading