Completed
Pull Request — master (#16)
by Sergii
04:26
created

DrupalKernelPlaceholder::jsonEncode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * @author Sergii Bondarenko, <[email protected]>
4
 */
5
namespace Drupal\TqExtension\Cores;
6
7
use Behat\Behat\Hook\Scope\BeforeFeatureScope;
8
use Drupal\TqExtension\Context\TqContext;
9
10
class DrupalKernelPlaceholder
11
{
12
    /**
13
     * Version-related implementation of @BeforeFeature hook for TqContext.
14
     *
15
     * @param BeforeFeatureScope $scope
16
     *
17
     * @see TqContext::beforeFeature()
18
     */
19
    public static function beforeFeature(BeforeFeatureScope $scope)
1 ignored issue
show
Unused Code introduced by
The parameter $scope is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
20
    {
21
        self::requireContext(__FUNCTION__, func_get_args());
22
    }
23
24
    /**
25
     * @param string $string
26
     * @param array $arguments
27
     * @param array $options
28
     *
29
     * @return string
30
     */
31
    public static function t($string, array $arguments = [], array $options = [])
32
    {
33
        return self::requireContext(__FUNCTION__, func_get_args());
34
    }
35
36
    /**
37
     * @param string $string
38
     * @param array $arguments
39
     *
40
     * @return string
41
     */
42
    public static function formatString($string, array $arguments = [])
43
    {
44
        return self::requireContext(__FUNCTION__, func_get_args());
45
    }
46
47
    /**
48
     * @return string[]
49
     */
50
    public static function arg()
51
    {
52
        return self::requireContext(__FUNCTION__, func_get_args());
53
    }
54
55
    /**
56
     * @param string $text
57
     *   Input text.
58
     * @param array $data
59
     *   Data for replacements.
60
     * @param array $options
61
     *   Replacement configuration.
62
     *
63
     * @return string
64
     *   Processed text.
65
     */
66
    public static function tokenReplace($text, array $data = [], array $options = [])
67
    {
68
        return self::requireContext(__FUNCTION__, func_get_args());
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public static function sitePath()
75
    {
76
        return self::requireContext(__FUNCTION__, func_get_args());
77
    }
78
79
    /**
80
     * @param mixed $data
81
     *
82
     * @return string
83
     */
84
    public static function jsonEncode($data)
85
    {
86
        return self::requireContext(__FUNCTION__, func_get_args());
87
    }
88
89
    public static function setCurrentUser($user)
90
    {
91
        self::requireContext(__FUNCTION__, func_get_args());
92
    }
93
94
    public static function setCurrentPath($path)
95
    {
96
        self::requireContext(__FUNCTION__, func_get_args());
97
    }
98
99
    /**
100
     * Locate user ID by its name.
101
     *
102
     * @param string $username
103
     *
104
     * @return int
105
     */
106
    public static function getUidByName($username)
107
    {
108
        return self::requireContext(__FUNCTION__, func_get_args());
109
    }
110
111
    /**
112
     * @param int $user_id
113
     */
114
    public static function deleteUser($user_id)
115
    {
116
        self::requireContext(__FUNCTION__, func_get_args());
117
    }
118
119
    /**
120
     * @param string $table
121
     * @param string $alias
122
     * @param array $options
123
     *
124
     * @return object
125
     */
126
    public static function selectQuery($table, $alias = null, array $options = [])
127
    {
128
        return self::requireContext(__FUNCTION__, func_get_args());
129
    }
130
131
    /**
132
     * @param string $entityType
133
     * @param string $bundle
134
     *
135
     * @return array[]
136
     *   An associative array where key - machine-name of a field and
137
     *   value - an array with two keys: "label" and "required".
138
     */
139
    public static function getFieldDefinitions($entityType, $bundle)
140
    {
141
        return self::requireContext(__FUNCTION__, func_get_args());
142
    }
143
144
    /**
145
     * Get information about database connections.
146
     *
147
     * Impossible to use $GLOBALS['databases'] in Drupal 8 since {@link https://www.drupal.org/node/2176621}.
148
     *
149
     * @param string $connection
150
     *   Connection name.
151
     *
152
     * @return array[]
153
     */
154
    public static function getDatabaseConnectionInfo($connection)
155
    {
156
        return self::requireContext(__FUNCTION__, func_get_args());
157
    }
158
159
    /**
160
     * @param string $entityType
161
     * @param int $id
162
     *
163
     * @return object
164
     */
165
    public static function entityLoad($entityType, $id)
166
    {
167
        return self::requireContext(__FUNCTION__, func_get_args());
168
    }
169
170
    /**
171
     * @param object $entity
172
     * @param string $fieldName
173
     *
174
     * @return bool
175
     */
176
    public static function entityHasField($entity, $fieldName)
177
    {
178
        return self::requireContext(__FUNCTION__, func_get_args());
179
    }
180
181
    /**
182
     * @param object $entity
183
     * @param string $fieldName
184
     *
185
     * @return mixed
186
     */
187
    public static function entityFieldValue($entity, $fieldName)
188
    {
189
        return self::requireContext(__FUNCTION__, func_get_args());
190
    }
191
192
    /**
193
     * Switching the mail system.
194
     *
195
     * @param bool $useTesting
196
     *   Whether testing or standard mail system should be used.
197
     */
198
    public static function switchMailSystem($useTesting)
199
    {
200
        self::requireContext(__FUNCTION__, func_get_args());
201
    }
202
203
    /**
204
     * Get a list of emails, collected by testing mail system.
205
     *
206
     * @return array
207
     */
208
    public static function getEmailMessages()
209
    {
210
        return self::requireContext(__FUNCTION__, func_get_args());
211
    }
212
213
    /**
214
     * Check existence of the content type by its machine name or title.
215
     *
216
     * @param string $contentType
217
     *   Machine name or title of the content type.
218
     *
219
     * @return string
220
     *   Machine name.
221
     */
222
    public static function getContentTypeName($contentType)
223
    {
224
        return self::requireContext(__FUNCTION__, func_get_args());
225
    }
226
227
    /**
228
     * @param string $file
229
     *   Existing file from "src/JavaScript" without ".js" extension.
230
     * @param bool $delete
231
     *   Whether injection should be deleted.
232
     */
233
    public static function injectCustomJavascript($file, $delete = false)
234
    {
235
        self::requireContext(__FUNCTION__, func_get_args());
236
    }
237
238
    /**
239
     * {@inheritdoc}
240
     */
241
    public static function drupalGetFilename($type, $name, $filename = null)
242
    {
243
        return drupal_get_filename($type, $name, $filename);
244
    }
245
246
    /**
247
     * {@inheritdoc}
248
     */
249
    public static function fileUnmanagedDelete($path)
250
    {
251
        return file_unmanaged_delete($path);
252
    }
253
254
    /**
255
     * {@inheritdoc}
256
     */
257
    public static function fileUnmanagedCopy($source, $destination = null, $replace = FILE_EXISTS_RENAME)
258
    {
259
        return file_unmanaged_copy($source, $destination, $replace);
260
    }
261
262
    /**
263
     * Require method execution from context.
264
     *
265
     * @param string $method
266
     *   The name of method.
267
     * @param array $arguments
268
     *   Method's arguments.
269
     *
270
     * @return mixed
271
     */
272
    private static function requireContext($method, array $arguments)
273
    {
274
        $context = str_replace('Kernel', DRUPAL_CORE, __CLASS__);
275
276
        if (method_exists($context, $method)) {
277
            return call_user_func_array([$context, $method], $arguments);
278
        }
279
280
        throw new \BadMethodCallException(sprintf('Method "%s" is not implemented in "%s".', $method, $context));
281
    }
282
}
283