diff --git a/drush/key.drush.inc b/drush/key.drush.inc index fc26f3c..1154f0b 100644 --- a/drush/key.drush.inc +++ b/drush/key.drush.inc @@ -1,5 +1,10 @@ FALSE, - 'fields' => [] + 'fields' => [], ]; } diff --git a/src/Commands/KeyCommands.php b/src/Commands/KeyCommands.php index 3d2186f..f3bc551 100644 --- a/src/Commands/KeyCommands.php +++ b/src/Commands/KeyCommands.php @@ -1,18 +1,18 @@ null, - 'description' => null, - 'key-type' => null, - 'key-type-settings' => null, - 'key-provider' => null, - 'key-provider-settings' => null, - 'key-input' => null, - 'key-input-settings' => null, + array $options = [ + 'label' => NULL, + 'description' => NULL, + 'key-type' => NULL, + 'key-type-settings' => NULL, + 'key-provider' => NULL, + 'key-provider-settings' => NULL, + 'key-input' => NULL, + 'key-input-settings' => NULL, ] ) { $values = []; @@ -177,12 +188,17 @@ class KeyCommands extends DrushCommands { /** * Delete a key. * + * @param string $id + * The ID (machine name) of the key to delete. + * @param array $options + * Options array. + * * @command key:delete - * @param string $id The ID (machine name) of the key to delete. + * * @aliases key-delete * @format table */ - public function delete($id, $options = []) { + public function delete($id, array $options = []) { // Look for a key with the specified ID. If one does not exist, set an // error and abort. /* @var $key \Drupal\key\Entity\Key */ @@ -195,7 +211,7 @@ class KeyCommands extends DrushCommands { $this->logger->warning('Be extremely careful when deleting a key! It may result in losing access to a service or making encrypted data unreadable.'); $this->output->writeln(dt('The following key will be deleted: !id', ['!id' => $id])); if (!$this->io()->confirm(dt('Do you want to continue?'))) { - // Removing drush_user_abort(), no current implemenation of that + // Removing drush_user_abort(), no current implemenation of that. return; } @@ -216,13 +232,16 @@ class KeyCommands extends DrushCommands { /** * Display a list of available keys. * + * @param array $options + * Options array. + * * @command key:list * @option key-type An optional, comma-delimited list of key types. To see a list of available key types, use `drush key-type-list`. * @option key-provider An optional, comma-delimited list of key providers. To see a list of available key providers, use `drush key-provider-list`. * @aliases key-list * @format table */ - public function keyList($options = ['key-type' => null, 'key-provider' => null]) { + public function keyList(array $options = ['key-type' => NULL, 'key-provider' => NULL]) { $result = []; /* @var $key \Drupal\key\Entity\Key */ @@ -268,7 +287,7 @@ class KeyCommands extends DrushCommands { * @aliases key-type-list * @format table */ - public function typeList($options = ['group' => null]) { + public function typeList($options = ['group' => NULL]) { $result = []; $group = $options['group']; @@ -295,7 +314,7 @@ class KeyCommands extends DrushCommands { * @aliases key-provider-list * @format table */ - public function providerList($options = ['storage-method' => null]) { + public function providerList($options = ['storage-method' => NULL]) { $result = []; $storage_method = $options['storage-method']; @@ -317,13 +336,18 @@ class KeyCommands extends DrushCommands { /** * Display a list of available key providers. * + * @param string $id + * The ID (machine name) of the key whose value should be retrieved. + * @param array $options + * Options array. + * * @command key:value-get - * @param string $id The ID (machine name) of the key whose value should be retrieved. + * * @option base64 Base64-encode the key value. This is useful in the case of binary encryption keys that would otherwise not be displayed in a readable way. * @aliases key-value-get, key-value * @format table */ - public function valueGet($id, $options = ['base64' => null]) { + public function valueGet($id, array $options = ['base64' => NULL]) { $result = []; // Look for a key with the specified ID. If one does not exist, set an // error and abort. @@ -343,7 +367,7 @@ class KeyCommands extends DrushCommands { } $row = []; - $row ['Key value'] = $key_value; + $row['Key value'] = $key_value; $result[] = $row; return new RowsOfFields($result); @@ -387,5 +411,4 @@ class KeyCommands extends DrushCommands { ]; } - } diff --git a/src/Controller/KeyConfigOverrideListBuilder.php b/src/Controller/KeyConfigOverrideListBuilder.php index 78b1d20..bd9d8b2 100644 --- a/src/Controller/KeyConfigOverrideListBuilder.php +++ b/src/Controller/KeyConfigOverrideListBuilder.php @@ -29,14 +29,14 @@ class KeyConfigOverrideListBuilder extends ConfigEntityListBuilder { /** * The configuration manager. * - * @var \Drupal\Core\Config\ConfigManagerInterface; + * @var \Drupal\Core\Config\ConfigManagerInterface */ protected $configManager; /** * The key repository. * - * @var \Drupal\key\KeyRepositoryInterface; + * @var \Drupal\key\KeyRepositoryInterface */ protected $keyRepository; diff --git a/src/Controller/KeyListBuilder.php b/src/Controller/KeyListBuilder.php index 1fce464..40ae599 100644 --- a/src/Controller/KeyListBuilder.php +++ b/src/Controller/KeyListBuilder.php @@ -25,6 +25,8 @@ class KeyListBuilder extends ConfigEntityListBuilder { protected $entityTypeManager; /** + * Overrides. + * * @var array */ protected $overrides; @@ -122,7 +124,6 @@ class KeyListBuilder extends ConfigEntityListBuilder { return $build; } - /** * Get any overrides associated with a key. * diff --git a/src/Element/KeySelect.php b/src/Element/KeySelect.php index eb7a1a2..b0f0f21 100644 --- a/src/Element/KeySelect.php +++ b/src/Element/KeySelect.php @@ -52,7 +52,7 @@ class KeySelect extends Select { * @return array * The processed element. */ - public static function processKeySelect(&$element, FormStateInterface $form_state, &$complete_form) { + public static function processKeySelect(array &$element, FormStateInterface $form_state, array &$complete_form) { // Get the list of available keys and define the options. $options = \Drupal::service('key.repository')->getKeyNamesAsOptions($element['#key_filters']); $element['#options'] = $options; diff --git a/src/Entity/Key.php b/src/Entity/Key.php index b4713a4..323efec 100644 --- a/src/Entity/Key.php +++ b/src/Entity/Key.php @@ -124,7 +124,7 @@ class Key extends ConfigEntityBase implements KeyInterface, EntityWithPluginColl /** * The key value. * - * @var string|NULL + * @var string|null */ protected $keyValue = NULL; diff --git a/src/Exception/KeyException.php b/src/Exception/KeyException.php index 7dc1e9c..bfc1971 100644 --- a/src/Exception/KeyException.php +++ b/src/Exception/KeyException.php @@ -5,4 +5,4 @@ namespace Drupal\key\Exception; /** * Defines a generic exception for Key. */ -class KeyException extends \Exception { } +class KeyException extends \Exception {} diff --git a/src/Exception/KeyValueNotDeletedException.php b/src/Exception/KeyValueNotDeletedException.php index c376189..8d7b917 100644 --- a/src/Exception/KeyValueNotDeletedException.php +++ b/src/Exception/KeyValueNotDeletedException.php @@ -5,4 +5,4 @@ namespace Drupal\key\Exception; /** * Defines an exception for when a key value fails to be deleted. */ -class KeyValueNotDeletedException extends KeyException { } +class KeyValueNotDeletedException extends KeyException {} diff --git a/src/Exception/KeyValueNotRetrievedException.php b/src/Exception/KeyValueNotRetrievedException.php index 7ae4c56..36ec519 100644 --- a/src/Exception/KeyValueNotRetrievedException.php +++ b/src/Exception/KeyValueNotRetrievedException.php @@ -5,4 +5,4 @@ namespace Drupal\key\Exception; /** * Defines an exception for when a key value fails to be retrieved. */ -class KeyValueNotRetrievedException extends KeyException { } +class KeyValueNotRetrievedException extends KeyException {} diff --git a/src/Exception/KeyValueNotSetException.php b/src/Exception/KeyValueNotSetException.php index ad1582a..8d4799c 100644 --- a/src/Exception/KeyValueNotSetException.php +++ b/src/Exception/KeyValueNotSetException.php @@ -5,4 +5,4 @@ namespace Drupal\key\Exception; /** * Defines an exception for when a key value fails to be set. */ -class KeyValueNotSetException extends KeyException { } +class KeyValueNotSetException extends KeyException {} diff --git a/src/Form/KeyConfigOverrideAddForm.php b/src/Form/KeyConfigOverrideAddForm.php index c2b517c..249c7c2 100644 --- a/src/Form/KeyConfigOverrideAddForm.php +++ b/src/Form/KeyConfigOverrideAddForm.php @@ -13,6 +13,9 @@ use Drupal\Core\StringTranslation\TranslatableMarkup; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RequestStack; +/** + * KeyConfigOverrideAddForm class. + */ class KeyConfigOverrideAddForm extends EntityForm { /** @@ -64,6 +67,10 @@ class KeyConfigOverrideAddForm extends EntityForm { * The entity manager. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory. + * @param \Drupal\Core\Config\StorageInterface $config_storage + * The config storage. + * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack + * The current request stack. */ public function __construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, StorageInterface $config_storage, RequestStack $request_stack) { $this->entityTypeManager = $entity_type_manager; @@ -194,7 +201,7 @@ class KeyConfigOverrideAddForm extends EntityForm { $definitions = $this->getConfigEntityTypeDefinitions(); $config_type = $form_state->getValue('config_type'); - if (key_exists($config_type, $definitions)) { + if (array_key_exists($config_type, $definitions)) { $config_prefix = $definitions[$config_type]->getConfigPrefix(); } else { @@ -308,7 +315,7 @@ class KeyConfigOverrideAddForm extends EntityForm { $names = $this->configStorage->listAll(); $names = array_combine($names, $names); - // Filter out any names that match a configuration entity prefix + // Filter out any names that match a configuration entity prefix. foreach ($names as $config_name) { foreach ($config_prefixes as $config_prefix) { if (strpos($config_name, $config_prefix) === 0) { @@ -361,7 +368,7 @@ class KeyConfigOverrideAddForm extends EntityForm { * Define the list of configuration types to exclude. * * @return array - * The configuration types to exclude. + * The configuration types to exclude. */ protected function excludedConfigTypes() { $exclude = [ @@ -374,7 +381,7 @@ class KeyConfigOverrideAddForm extends EntityForm { /** * Recursively create a flat array of configuration items. * - * @param $config_array + * @param array $config_array * An array of configuration items. * @param string $prefix * A prefix to add to nested items. @@ -384,7 +391,7 @@ class KeyConfigOverrideAddForm extends EntityForm { * @return array * The flattened array of configuration items. */ - protected function flattenConfigItemList($config_array, $prefix = '', $level = 0) { + protected function flattenConfigItemList(array $config_array, $prefix = '', $level = 0) { $config_items = []; // Define items to ignore. diff --git a/src/Form/KeyConfigOverrideDeleteForm.php b/src/Form/KeyConfigOverrideDeleteForm.php index cb9d6d1..ba37614 100644 --- a/src/Form/KeyConfigOverrideDeleteForm.php +++ b/src/Form/KeyConfigOverrideDeleteForm.php @@ -3,13 +3,13 @@ namespace Drupal\key\Form; use Drupal\Core\Entity\EntityDeleteForm; -use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** * Builds the form to delete a Key. */ class KeyConfigOverrideDeleteForm extends EntityDeleteForm { + /** * {@inheritdoc} */ diff --git a/src/Form/KeyFormBase.php b/src/Form/KeyFormBase.php index 0812b03..dc4a6ca 100644 --- a/src/Form/KeyFormBase.php +++ b/src/Form/KeyFormBase.php @@ -6,7 +6,6 @@ use Drupal\Core\Entity\EntityForm; use Drupal\Core\Config\Entity\ConfigEntityStorageInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\key\Entity\Key; -use Drupal\key\Exception\KeyValueNotSetException; use Drupal\key\Plugin\KeyPluginFormInterface; use Drupal\key\Plugin\KeyProviderSettableValueInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -26,7 +25,7 @@ abstract class KeyFormBase extends EntityForm { /** * The original key. * - * @var \Drupal\key\Entity\Key|NULL + * @var \Drupal\key\Entity\Key|null * The original key entity or NULL if this is a new key. */ protected $originalKey = NULL; @@ -486,10 +485,10 @@ abstract class KeyFormBase extends EntityForm { * * @param string $type * The plugin type ID. - * @param FormStateInterface $form_state + * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state to copy values from. * - * @return FormStateInterface + * @return \Drupal\Core\Form\FormStateInterface * A clone of the form state object with values from the plugin. */ protected function createPluginFormState($type, FormStateInterface $form_state) { diff --git a/src/KeyConfigOverrideInterface.php b/src/KeyConfigOverrideInterface.php index fa370bd..3fca7bd 100644 --- a/src/KeyConfigOverrideInterface.php +++ b/src/KeyConfigOverrideInterface.php @@ -4,11 +4,14 @@ namespace Drupal\key; use Drupal\Core\Config\Entity\ConfigEntityInterface; +/** + * KeyConfigOverrideInterface interface. + */ interface KeyConfigOverrideInterface extends ConfigEntityInterface { /** * Gets the configuration type. - * + * * @return string * The configuration type. */ @@ -16,7 +19,7 @@ interface KeyConfigOverrideInterface extends ConfigEntityInterface { /** * Gets the configuration name. - * + * * @return string * The configuration name. */ diff --git a/src/KeyConfigOverrides.php b/src/KeyConfigOverrides.php index 7bb89bf..3405b0c 100644 --- a/src/KeyConfigOverrides.php +++ b/src/KeyConfigOverrides.php @@ -15,21 +15,29 @@ use Drupal\Core\Config\StorageInterface; class KeyConfigOverrides implements ConfigFactoryOverrideInterface { /** + * Config factory. + * * @var \Drupal\Core\Config\ConfigFactoryInterface */ protected $configFactory; /** + * Cache backend. + * * @var \Drupal\Core\Cache\CacheBackendInterface */ protected $cacheBackend; /** + * Mapping. + * * @var array */ protected $mapping; /** + * In override. + * * @var bool */ protected $inOverride = FALSE; @@ -71,7 +79,7 @@ class KeyConfigOverrides implements ConfigFactoryOverrideInterface { $overrides = []; foreach ($names as $name) { - if (!key_exists($name, $mapping)) { + if (!array_key_exists($name, $mapping)) { continue; } diff --git a/src/KeyRepository.php b/src/KeyRepository.php index 3dcb239..7ff4be2 100644 --- a/src/KeyRepository.php +++ b/src/KeyRepository.php @@ -118,7 +118,7 @@ class KeyRepository implements KeyRepositoryInterface { /** * {@inheritdoc} */ - public function getKeyNamesAsOptions($filters = []) { + public function getKeyNamesAsOptions(array $filters = []) { $options = []; $keys = $this->getKeys(); @@ -127,12 +127,15 @@ class KeyRepository implements KeyRepositoryInterface { case 'type': $keys = array_intersect_key($this->getKeysByType($filter), $keys); break; + case 'provider': $keys = array_intersect_key($this->getKeysByProvider($filter), $keys); break; + case 'type_group': $keys = array_intersect_key($this->getKeysByTypeGroup($filter), $keys); break; + case 'storage_method': $keys = array_intersect_key($this->getKeysByStorageMethod($filter), $keys); break; diff --git a/src/KeyRepositoryInterface.php b/src/KeyRepositoryInterface.php index ae19308..47551a3 100644 --- a/src/KeyRepositoryInterface.php +++ b/src/KeyRepositoryInterface.php @@ -84,9 +84,9 @@ interface KeyRepositoryInterface { * @param array $filters * An array of filters to apply to the list of options. * - * @return array An array of key names, indexed by id. + * @return array * An array of key names, indexed by id. */ - public function getKeyNamesAsOptions($filters); + public function getKeyNamesAsOptions(array $filters); } diff --git a/src/Plugin/KeyPluginCollection.php b/src/Plugin/KeyPluginCollection.php index f93acfd..68499ec 100644 --- a/src/Plugin/KeyPluginCollection.php +++ b/src/Plugin/KeyPluginCollection.php @@ -9,16 +9,6 @@ use Drupal\Core\Plugin\DefaultSingleLazyPluginCollection; */ class KeyPluginCollection extends DefaultSingleLazyPluginCollection { - /** - * {@inheritdoc} - * - * @return \Drupal\key\Plugin\KeyPluginInterface - * A Key plugin instance. - */ - public function &get($instance_id) { - return parent::get($instance_id); - } - /** * {@inheritdoc} */ diff --git a/src/Plugin/KeyPluginInterface.php b/src/Plugin/KeyPluginInterface.php index 7d8b35f..e2ba0c8 100644 --- a/src/Plugin/KeyPluginInterface.php +++ b/src/Plugin/KeyPluginInterface.php @@ -2,14 +2,15 @@ namespace Drupal\key\Plugin; -use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Component\Plugin\ConfigurableInterface; +use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Component\Plugin\PluginInspectionInterface; -use Drupal\Component\Plugin\ConfigurablePluginInterface; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; /** * Provides an interface for all Key plugins. */ -interface KeyPluginInterface extends ContainerFactoryPluginInterface, PluginInspectionInterface, ConfigurablePluginInterface { +interface KeyPluginInterface extends ContainerFactoryPluginInterface, PluginInspectionInterface, ConfigurableInterface, DependentPluginInterface { /** * Returns the type of plugin. diff --git a/src/Plugin/KeyType/AuthenticationMultivalueKeyType.php b/src/Plugin/KeyType/AuthenticationMultivalueKeyType.php index 1aee697..7aa888a 100644 --- a/src/Plugin/KeyType/AuthenticationMultivalueKeyType.php +++ b/src/Plugin/KeyType/AuthenticationMultivalueKeyType.php @@ -4,7 +4,6 @@ namespace Drupal\key\Plugin\KeyType; use Drupal\Component\Serialization\Json; use Drupal\Core\Form\FormStateInterface; -use Drupal\key\Plugin\KeyPluginFormInterface; use Drupal\key\Plugin\KeyTypeBase; use Drupal\key\Plugin\KeyTypeMultivalueInterface; @@ -61,7 +60,7 @@ class AuthenticationMultivalueKeyType extends KeyTypeBase implements KeyTypeMult $definition = $this->getPluginDefinition(); $fields = $definition['multivalue']['fields']; - foreach($fields as $id => $field) { + foreach ($fields as $id => $field) { if (!is_array($field)) { $field = ['label' => $field]; } @@ -70,7 +69,7 @@ class AuthenticationMultivalueKeyType extends KeyTypeBase implements KeyTypeMult continue; } - if (!isset ($value[$id])) { + if (!isset($value[$id])) { $form_state->setError($error_element, $this->t('The key value is missing the field %field.', ['%field' => $id])); } elseif (empty($value[$id])) { diff --git a/src/Plugin/KeyType/EncryptionKeyType.php b/src/Plugin/KeyType/EncryptionKeyType.php index 377c8fd..77a0d2a 100644 --- a/src/Plugin/KeyType/EncryptionKeyType.php +++ b/src/Plugin/KeyType/EncryptionKeyType.php @@ -62,8 +62,8 @@ class EncryptionKeyType extends KeyTypeBase implements KeyPluginFormInterface { '#title_display' => 'invisible', '#description' => $this->t('Enter a custom key size in bits.'), '#default_value' => $key_size_other_value, - '#maxlength'=> 20, - '#size'=> 20, + '#maxlength' => 20, + '#size' => 20, '#states' => [ 'visible' => [ 'select[name="key_type_settings[key_size]"]' => ['value' => 'other'], diff --git a/src/Plugin/KeyTypeMultivalueInterface.php b/src/Plugin/KeyTypeMultivalueInterface.php index e8bbe2e..2577f21 100644 --- a/src/Plugin/KeyTypeMultivalueInterface.php +++ b/src/Plugin/KeyTypeMultivalueInterface.php @@ -11,7 +11,7 @@ interface KeyTypeMultivalueInterface { * Serialize an array of key values into a string. * * @param array $array - * An array of key values + * An array of key values. * * @return string * A serialized string of key values. diff --git a/tests/assets/testkey.txt b/tests/assets/testkey.txt index 3d2ad72..5406af6 100644 --- a/tests/assets/testkey.txt +++ b/tests/assets/testkey.txt @@ -2,4 +2,4 @@ abc def ghi jkl mno pqr stu vwx yz1@3$ abc def ghi jkl mno pqr stu vwx yz5^7* -abc def ghi jkl mno pqr stu vwx yz9) \ No newline at end of file +abc def ghi jkl mno pqr stu vwx yz9) diff --git a/tests/src/Unit/Entity/KeyEntityTest.php b/tests/src/Unit/Entity/KeyEntityTest.php index cd91205..6c2d768 100644 --- a/tests/src/Unit/Entity/KeyEntityTest.php +++ b/tests/src/Unit/Entity/KeyEntityTest.php @@ -15,34 +15,46 @@ use Drupal\Tests\key\Unit\KeyTestBase; class KeyEntityTest extends KeyTestBase { /** + * Key type manager. + * * @var \Drupal\key\Plugin\KeyPluginManager */ protected $keyTypeManager; /** + * Key provider manager. + * * @var \Drupal\key\Plugin\KeyPluginManager */ protected $keyProviderManager; /** + * Key plugin manager. + * * @var \Drupal\key\Plugin\KeyPluginManager */ protected $keyInputManager; /** - * @var [] + * Key type settings. + * + * @var array * Key type settings to use for Authentication key type. */ protected $key_type_settings; /** - * @var [] + * Key provider settings. + * + * @var array * Key provider settings to use for Configuration key provider. */ protected $key_provider_settings; /** - * @var [] + * Key input settings. + * + * @var array * Key input settings to use for None key input. */ protected $key_input_settings; @@ -110,7 +122,11 @@ class KeyEntityTest extends KeyTestBase { ->method('getDefinitions') ->willReturn([ ['id' => 'file', 'label' => 'File', 'storage_method' => 'file'], - ['id' => 'config', 'label' => 'Configuration', 'storage_method' => 'config'], + [ + 'id' => 'config', + 'label' => 'Configuration', + 'storage_method' => 'config', + ], ]); $this->keyProviderManager->expects($this->any()) ->method('createInstance') diff --git a/tests/src/Unit/KeyTestBase.php b/tests/src/Unit/KeyTestBase.php index a5a400c..e984859 100644 --- a/tests/src/Unit/KeyTestBase.php +++ b/tests/src/Unit/KeyTestBase.php @@ -11,25 +11,33 @@ use Drupal\Tests\UnitTestCase; abstract class KeyTestBase extends UnitTestCase { /** + * Config. + * * @var \Drupal\Core\Config\ImmutableConfig */ protected $config; /** + * Configuration storage. + * * @var \Drupal\Core\Config\Entity\ConfigEntityStorage */ protected $configStorage; /** + * Entity type manager instance. + * * @var \Drupal\Core\Entity\EntityTypeManager */ protected $entityTypeManager; /** - * @var \Drupal\Core\DependencyInjection\ContainerBuilder + * Container builder. * * This should be used sparingly by test cases to add to the container as * necessary for tests. + * + * @var \Drupal\Core\DependencyInjection\ContainerBuilder */ protected $container;