Skip to content

Commit f29af10

Browse files
authored
Better string handling and Scrutinizer fixes. (drupal-graphql#279)
1 parent b0c69cb commit f29af10

File tree

87 files changed

+400
-293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+400
-293
lines changed

.scrutinizer.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
filter:
2+
excluded_paths:
3+
- 'tests/*'
4+
5+
checks:
6+
php: true

.travis.yml

+17-35
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,28 @@
11
language: php
22
sudo: false
33

4+
php:
5+
- 5.5
6+
- 5.6
7+
- 7
8+
9+
env:
10+
- DRUPAL_CORE=8.2.x
11+
- DRUPAL_CORE=8.3.x
12+
- DRUPAL_CORE=8.4.x
13+
414
matrix:
515
# Don't wait for the allowed failures to build.
616
fast_finish: true
717
include:
8-
- php: 5.5
9-
env:
10-
- DRUPAL_CORE=8.2.x
11-
- php: 5.5
12-
env:
13-
- DRUPAL_CORE=8.3.x
14-
- php: 5.5
15-
env:
16-
- DRUPAL_CORE=8.4.x
17-
- php: 5.6
18-
env:
19-
- DRUPAL_CORE=8.2.x
20-
- php: 5.6
21-
env:
22-
- DRUPAL_CORE=8.3.x
23-
- php: 5.6
24-
env:
25-
- DRUPAL_CORE=8.4.x
26-
- php: 7
27-
env:
28-
- DRUPAL_CORE=8.2.x
29-
- php: 7
30-
env:
31-
- DRUPAL_CORE=8.3.x
32-
- php: 7
33-
env:
34-
- DRUPAL_CORE=8.4.x
3518
- php: 7
3619
env:
3720
- DRUPAL_CORE=8.4.x
3821
# Only run code coverage on the latest php and drupal versions.
3922
- WITH_PHPDBG_COVERAGE=true
23+
allow_failures:
24+
# Allow the code coverage report to fail.
25+
- env: WITH_PHPDBG_COVERAGE=true DRUPAL_CORE=8.4.x
4026

4127
mysql:
4228
database: graphql
@@ -101,10 +87,6 @@ before_script:
10187
# Export web server URL for browser tests.
10288
- export SIMPLETEST_BASE_URL=http://localhost:8888
10389

104-
# Install PHPCS to check for Drupal coding standards.
105-
- travis_retry composer global require drupal/coder
106-
- $HOME/.composer/vendor/bin/phpcs --config-set installed_paths $HOME/.composer/vendor/drupal/coder/coder_sniffer
107-
10890
script:
10991
# Run the unit tests which also include the kernel tests. When running with
11092
# phpdbg we need to replace all code occurrences that check for 'cli' with
@@ -117,10 +99,10 @@ script:
11799
vendor/bin/phpunit --configuration core/phpunit.xml.dist modules/graphql;
118100
fi
119101

120-
# Check for coding standards violations
121-
- cd modules/graphql && $HOME/.composer/vendor/bin/phpcs
122-
123102
after_success:
124103
- if [[ "$WITH_PHPDBG_COVERAGE" == "true" ]];
125-
then bash <(curl -s https://codecov.io/bash);
104+
then
105+
bash <(curl -s https://codecov.io/bash);
106+
wget https://scrutinizer-ci.com/ocular.phar;
107+
php ocular.phar code-coverage:upload --format=php-clover coverage.xml;
126108
fi

graphql.module

+8-16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* @file
55
* The GraphQL module.
66
*/
7+
use Drupal\graphql\Utility\StringHelper;
78

89
/**
910
* Implements hook_help().
@@ -32,28 +33,19 @@ EOT;
3233
/**
3334
* Turn a list of machine names into a camel-cased string.
3435
*
35-
* @param string[]|string $components
36-
* Name components to be concatenated.
37-
*
38-
* @return string
39-
* A camel-cased concatenation of the input components.
36+
* @deprecated in graphql 3.x and will be removed before 3.0-alpha6.
37+
* Use \Drupal\graphql\Utility\StringHelper::camelCase() instead.
4038
*/
4139
function graphql_camelcase($components) {
42-
$components = is_array($components) ? implode('_', $components) : $components;
43-
$components = preg_split('/[^a-zA-Z0-9]/', $components);
44-
45-
return implode('', array_map('ucfirst', $components));
40+
return StringHelper::camelCase($components);
4641
}
4742

4843
/**
4944
* Turn a list of machine names into a property-cased string.
5045
*
51-
* @param string[]|string $components
52-
* Name components to be concatenated.
53-
*
54-
* @return string
55-
* A camel-cased concatenation of the input components.
46+
* @deprecated in graphql 3.x and will be removed before 3.0-alpha6.
47+
* Use \Drupal\graphql\Utility\StringHelper::propCase() instead.
5648
*/
5749
function graphql_propcase($components) {
58-
return lcfirst(graphql_camelcase($components));
59-
}
50+
return StringHelper::propCase($components);
51+
}

modules/graphql_block/src/Plugin/GraphQL/Fields/BlocksByRegion.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ protected function resolveSubrequest($value, array $args, ResolveInfo $info) {
116116
'region' => $region,
117117
]);
118118

119-
$blocks = array_filter($blocks, function (Block $block) {
120-
return array_reduce(iterator_to_array($block->getVisibilityConditions()), function ($value, ConditionInterface $condition) {
119+
$blocks = array_filter($blocks, function(Block $block) {
120+
return array_reduce(iterator_to_array($block->getVisibilityConditions()), function($value, ConditionInterface $condition) {
121121
return $value && (!$condition->isNegated() == $condition->evaluate());
122122
}, TRUE);
123123
});
124124

125125
uasort($blocks, '\Drupal\Block\Entity\Block::sort');
126126

127-
$result = array_map(function (Block $block) {
127+
$result = array_map(function(Block $block) {
128128
$plugin = $block->getPlugin();
129129
if ($plugin instanceof BlockContentBlock) {
130130
return $this->entityRepository->loadEntityByUuid('block_content', $plugin->getDerivativeId());

modules/graphql_breadcrumbs/src/Plugin/GraphQL/Fields/Label.php

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Drupal\graphql_breadcrumbs\Plugin\GraphQL\Fields;
44

55
use Drupal\graphql_core\GraphQL\FieldPluginBase;
6-
use Drupal\link\LinkItemInterface;
76
use Youshido\GraphQL\Execution\ResolveInfo;
87
use Drupal\Core\Link;
98

modules/graphql_breadcrumbs/src/Plugin/GraphQL/Fields/Url.php

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Drupal\graphql_breadcrumbs\Plugin\GraphQL\Fields;
44

55
use Drupal\graphql_core\GraphQL\FieldPluginBase;
6-
use Drupal\link\LinkItemInterface;
76
use Youshido\GraphQL\Execution\ResolveInfo;
87
use Drupal\Core\Link;
98

modules/graphql_breadcrumbs/tests/src/Kernel/BreadcrumbsTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected function setUp() {
3939
$breadcrumbManager = $this->prophesize('Drupal\Core\Breadcrumb\BreadcrumbManager');
4040

4141
$breadcrumbManager->build(Argument::any())
42-
->will(function ($args) {
42+
->will(function($args) {
4343
/** @var RouteMatch $routeMatch */
4444
$routeMatch = $args[0];
4545
$breadcrumb = new Breadcrumb();

modules/graphql_content/src/ContentEntitySchemaConfig.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,20 @@ public function isEntityBundleExposed($entityType, $bundle) {
6464
* @param string $bundle
6565
* The bundle machine name.
6666
*
67-
* @return string
68-
* The view mode machine name, or FALSE if no fields are exposed.
67+
* @return string|null
68+
* The view mode machine name, or NULL if no fields are exposed.
6969
*/
7070
public function getExposedViewMode($entityType, $bundle) {
7171
if (!$this->isEntityBundleExposed($entityType, $bundle)) {
72-
return FALSE;
72+
return NULL;
7373
}
7474

7575
$viewMode = NestedArray::getValue($this->types, [
7676
$entityType, 'bundles', $bundle, 'view_mode',
7777
]);
7878

7979
if (!$viewMode || $viewMode == '__none__') {
80-
return FALSE;
80+
return NULL;
8181
}
8282

8383
list($type, $mode) = explode('.', $viewMode);

modules/graphql_content/src/Form/ContentEntitySchemaConfigForm.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Drupal\Core\Entity\EntityTypeManagerInterface;
1111
use Drupal\Core\Form\ConfigFormBase;
1212
use Drupal\Core\Form\FormStateInterface;
13+
use Drupal\graphql\Utility\StringHelper;
1314
use Symfony\Component\DependencyInjection\ContainerInterface;
1415

1516
/**
@@ -115,7 +116,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
115116
'#default_value' => isset($defaults[$type->id()]['exposed']) ? $defaults[$type->id()]['exposed'] : 0,
116117
'#title' => '<strong>' . $type->getLabel() . '</strong>',
117118
'#description' => $this->t('Add the <strong>%interface</strong> interface to the schema.', [
118-
'%interface' => graphql_camelcase($type->id()),
119+
'%interface' => StringHelper::camelCase($type->id()),
119120
]),
120121
'#wrapper_attributes' => ['colspan' => 2, 'class' => ['highlight']],
121122
];
@@ -134,7 +135,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
134135
],
135136
'#title' => $info['label'],
136137
'#description' => $this->t('Add the <strong>%type</strong> type to the schema.', [
137-
'%type' => graphql_camelcase([$type->id(), $bundle]),
138+
'%type' => StringHelper::camelCase([$type->id(), $bundle]),
138139
]),
139140
];
140141

modules/graphql_content/src/Plugin/Deriver/DisplayedFieldDeriver.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
use Drupal\Component\Plugin\Derivative\DeriverBase;
66
use Drupal\Core\Entity\ContentEntityTypeInterface;
77
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
8-
use Drupal\Core\Entity\Entity\EntityViewDisplay;
98
use Drupal\Core\Entity\EntityFieldManagerInterface;
109
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
1110
use Drupal\Core\Entity\EntityTypeManagerInterface;
1211
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
12+
use Drupal\graphql\Utility\StringHelper;
1313
use Drupal\graphql_content\ContentEntitySchemaConfig;
1414
use Symfony\Component\DependencyInjection\ContainerInterface;
1515

@@ -132,8 +132,8 @@ public function getDerivativeDefinitions($basePluginDefinition) {
132132
if ($display = $this->getDisplay($typeId, $bundle, $viewMode)) {
133133
foreach (array_keys($display->getComponents()) as $field) {
134134
$this->derivatives[$typeId . '-' . $bundle . '-' . $field] = [
135-
'name' => graphql_propcase($field),
136-
'types' => [graphql_camelcase([$typeId, $bundle])],
135+
'name' => StringHelper::propCase($field),
136+
'types' => [StringHelper::camelCase([$typeId, $bundle])],
137137
'entity_type' => $typeId,
138138
'bundle' => $bundle,
139139
'field' => $field,

modules/graphql_content/src/Plugin/Deriver/EntityBundleDeriver.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
88
use Drupal\Core\Entity\EntityTypeManagerInterface;
99
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
10+
use Drupal\graphql\Utility\StringHelper;
1011
use Drupal\graphql_content\ContentEntitySchemaConfig;
1112
use Symfony\Component\DependencyInjection\ContainerInterface;
1213

@@ -81,9 +82,9 @@ public function getDerivativeDefinitions($basePluginDefinition) {
8182
continue;
8283
}
8384
$this->derivatives[$typeId . '-' . $bundle] = [
84-
'name' => graphql_camelcase([$typeId, $bundle]),
85+
'name' => StringHelper::camelCase([$typeId, $bundle]),
8586
'entity_type' => $typeId,
86-
'interfaces' => [graphql_camelcase($typeId)],
87+
'interfaces' => [StringHelper::camelCase($typeId)],
8788
'bundle' => $bundle,
8889
] + $basePluginDefinition;
8990
}

modules/graphql_content/src/Plugin/Deriver/EntityByIdDeriver.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Drupal\Core\Entity\ContentEntityTypeInterface;
77
use Drupal\Core\Entity\EntityTypeManagerInterface;
88
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
9+
use Drupal\graphql\Utility\StringHelper;
910
use Drupal\graphql_content\ContentEntitySchemaConfig;
1011
use Symfony\Component\DependencyInjection\ContainerInterface;
1112

@@ -59,8 +60,8 @@ public function getDerivativeDefinitions($basePluginDefinition) {
5960
}
6061
if ($type instanceof ContentEntityTypeInterface) {
6162
$derivative = [
62-
'name' => graphql_propcase($id) . 'ById',
63-
'type' => graphql_camelcase($id),
63+
'name' => StringHelper::propCase([$id, 'by', 'id']),
64+
'type' => StringHelper::camelCase($id),
6465
'entity_type' => $id,
6566
] + $basePluginDefinition;
6667

modules/graphql_content/src/Plugin/Deriver/EntityTypeDeriver.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
namespace Drupal\graphql_content\Plugin\Deriver;
44

55
use Drupal\Component\Plugin\Derivative\DeriverBase;
6-
use Drupal\Core\Config\ConfigFactoryInterface;
76
use Drupal\Core\Entity\ContentEntityTypeInterface;
87
use Drupal\Core\Entity\EntityTypeManagerInterface;
98
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
9+
use Drupal\graphql\Utility\StringHelper;
1010
use Drupal\graphql_content\ContentEntitySchemaConfig;
1111
use Symfony\Component\DependencyInjection\ContainerInterface;
1212

@@ -70,7 +70,7 @@ public function getDerivativeDefinitions($basePluginDefinition) {
7070
}
7171
if ($type instanceof ContentEntityTypeInterface) {
7272
$this->derivatives[$typeId] = [
73-
'name' => graphql_camelcase($typeId),
73+
'name' => StringHelper::camelCase($typeId),
7474
'data_type' => 'entity:' . $typeId,
7575
'entity_type' => $typeId,
7676
] + $basePluginDefinition;

modules/graphql_content/src/Plugin/Deriver/FieldFormatterDeriver.php

+14-11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Drupal\Core\Field\FieldStorageDefinitionInterface;
88
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
99
use Drupal\Core\Entity\EntityFieldManagerInterface;
10+
use Drupal\graphql\Utility\StringHelper;
1011
use Drupal\graphql_content\ContentEntitySchemaConfig;
1112
use Symfony\Component\DependencyInjection\ContainerInterface;
1213

@@ -90,20 +91,22 @@ public function __construct(
9091
* @param \Drupal\Core\Field\FieldStorageDefinitionInterface|null $storage
9192
* Field storage definition object.
9293
*
93-
* @return array
94+
* @return array|null
9495
* Associative array of additional plugin definition values.
9596
*/
9697
protected function getDefinition($entityType, $bundle, array $displayOptions, FieldStorageDefinitionInterface $storage = NULL) {
97-
return [
98-
'types' => [
99-
graphql_camelcase([$entityType, $bundle]),
100-
],
101-
'name' => graphql_propcase($storage->getName()),
102-
'virtual' => !$storage,
103-
'multi' => $storage ? $storage->getCardinality() != 1 : FALSE,
104-
'nullable' => TRUE,
105-
'field' => $storage->getName(),
106-
];
98+
if (isset($storage)) {
99+
return [
100+
'types' => [StringHelper::camelCase([$entityType, $bundle])],
101+
'name' => graphql_propcase($storage->getName()),
102+
'virtual' => !$storage,
103+
'multi' => $storage ? $storage->getCardinality() != 1 : FALSE,
104+
'nullable' => TRUE,
105+
'field' => $storage->getName(),
106+
];
107+
}
108+
109+
return NULL;
107110
}
108111

109112
/**

modules/graphql_content/src/Plugin/Deriver/RawValueFieldDeriver.php

+15-12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Drupal\graphql_content\Plugin\Deriver;
44

55
use Drupal\Core\Field\FieldStorageDefinitionInterface;
6+
use Drupal\graphql\Utility\StringHelper;
67
use Drupal\graphql_content\Plugin\GraphQL\Types\RawValueFieldType;
78

89
/**
@@ -22,21 +23,23 @@ class RawValueFieldDeriver extends FieldFormatterDeriver {
2223
* @param \Drupal\Core\Field\FieldStorageDefinitionInterface|null $storage
2324
* Field storage definition object.
2425
*
25-
* @return array
26+
* @return array|null
2627
* Associative array of additional plugin definition values.
2728
*/
2829
protected function getDefinition($entityType, $bundle, array $displayOptions, FieldStorageDefinitionInterface $storage = NULL) {
29-
return [
30-
'types' => [
31-
graphql_camelcase([$entityType, $bundle]),
32-
],
33-
'name' => graphql_propcase($storage->getName()),
34-
'virtual' => !$storage,
35-
'multi' => $storage ? $storage->getCardinality() != 1 : FALSE,
36-
'nullable' => TRUE,
37-
'field' => $storage->getName(),
38-
'type' => RawValueFieldType::getId($entityType, $storage->getName()),
39-
];
30+
if (isset($storage)) {
31+
return [
32+
'types' => [StringHelper::camelCase([$entityType, $bundle])],
33+
'name' => graphql_propcase($storage->getName()),
34+
'virtual' => !$storage,
35+
'multi' => $storage ? $storage->getCardinality() != 1 : FALSE,
36+
'nullable' => TRUE,
37+
'field' => $storage->getName(),
38+
'type' => RawValueFieldType::getId($entityType, $storage->getName()),
39+
];
40+
}
41+
42+
return NULL;
4043
}
4144

4245
}

0 commit comments

Comments
 (0)