Skip to content

Commit 04aab9f

Browse files
committed
Rearrange class methods order to match the standard one (public > protected > private)
1 parent 3e64225 commit 04aab9f

File tree

9 files changed

+214
-218
lines changed

9 files changed

+214
-218
lines changed

.php_cs.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ return PhpCsFixer\Config::create()
4646
'no_useless_return' => true,
4747
'no_whitespace_in_blank_line' => true,
4848
'object_operator_without_whitespace' => true,
49+
'ordered_class_elements' => true,
4950
'ordered_imports' => true,
5051
'php_unit_construct' => true,
5152
'php_unit_dedicate_assert' => true,

lib/Remote/DesiredCapabilities.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -175,30 +175,6 @@ public function toArray()
175175
return $this->capabilities;
176176
}
177177

178-
/**
179-
* @param string $key
180-
* @param mixed $value
181-
* @return DesiredCapabilities
182-
*/
183-
private function set($key, $value)
184-
{
185-
$this->capabilities[$key] = $value;
186-
187-
return $this;
188-
}
189-
190-
/**
191-
* @param string $key
192-
* @param mixed $default
193-
* @return mixed
194-
*/
195-
private function get($key, $default = null)
196-
{
197-
return isset($this->capabilities[$key])
198-
? $this->capabilities[$key]
199-
: $default;
200-
}
201-
202178
/**
203179
* @return DesiredCapabilities
204180
*/
@@ -339,4 +315,28 @@ public static function phantomjs()
339315
WebDriverCapabilityType::PLATFORM => WebDriverPlatform::ANY,
340316
]);
341317
}
318+
319+
/**
320+
* @param string $key
321+
* @param mixed $value
322+
* @return DesiredCapabilities
323+
*/
324+
private function set($key, $value)
325+
{
326+
$this->capabilities[$key] = $value;
327+
328+
return $this;
329+
}
330+
331+
/**
332+
* @param string $key
333+
* @param mixed $default
334+
* @return mixed
335+
*/
336+
private function get($key, $default = null)
337+
{
338+
return isset($this->capabilities[$key])
339+
? $this->capabilities[$key]
340+
: $default;
341+
}
342342
}

lib/Remote/RemoteWebDriver.php

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -126,26 +126,6 @@ public static function create(
126126
return $driver;
127127
}
128128

129-
/**
130-
* Cast legacy types (array or null) to DesiredCapabilities object. To be removed in future when instance of
131-
* DesiredCapabilities will be required.
132-
*
133-
* @param array|DesiredCapabilities|null $desired_capabilities
134-
* @return DesiredCapabilities
135-
*/
136-
protected static function castToDesiredCapabilitiesObject($desired_capabilities = null)
137-
{
138-
if ($desired_capabilities === null) {
139-
return new DesiredCapabilities();
140-
}
141-
142-
if (is_array($desired_capabilities)) {
143-
return new DesiredCapabilities($desired_capabilities);
144-
}
145-
146-
return $desired_capabilities;
147-
}
148-
149129
/**
150130
* [Experimental] Construct the RemoteWebDriver by an existing session.
151131
*
@@ -293,29 +273,6 @@ public function quit()
293273
$this->executor = null;
294274
}
295275

296-
/**
297-
* Prepare arguments for JavaScript injection
298-
*
299-
* @param array $arguments
300-
* @return array
301-
*/
302-
private function prepareScriptArguments(array $arguments)
303-
{
304-
$args = [];
305-
foreach ($arguments as $key => $value) {
306-
if ($value instanceof WebDriverElement) {
307-
$args[$key] = ['ELEMENT' => $value->getID()];
308-
} else {
309-
if (is_array($value)) {
310-
$value = $this->prepareScriptArguments($value);
311-
}
312-
$args[$key] = $value;
313-
}
314-
}
315-
316-
return $args;
317-
}
318-
319276
/**
320277
* Inject a snippet of JavaScript into the page for execution in the context
321278
* of the currently selected frame. The executed script is assumed to be
@@ -469,18 +426,6 @@ public function getTouch()
469426
return $this->touch;
470427
}
471428

472-
/**
473-
* @return RemoteExecuteMethod
474-
*/
475-
protected function getExecuteMethod()
476-
{
477-
if (!$this->executeMethod) {
478-
$this->executeMethod = new RemoteExecuteMethod($this);
479-
}
480-
481-
return $this->executeMethod;
482-
}
483-
484429
/**
485430
* Construct a new action builder.
486431
*
@@ -491,17 +436,6 @@ public function action()
491436
return new WebDriverActions($this);
492437
}
493438

494-
/**
495-
* Return the WebDriverElement with the given id.
496-
*
497-
* @param string $id The id of the element to be created.
498-
* @return RemoteWebElement
499-
*/
500-
protected function newElement($id)
501-
{
502-
return new RemoteWebElement($this->getExecuteMethod(), $id);
503-
}
504-
505439
/**
506440
* Set the command executor of this RemoteWebdriver
507441
*
@@ -601,4 +535,70 @@ public function execute($command_name, $params = [])
601535

602536
return null;
603537
}
538+
539+
/**
540+
* Prepare arguments for JavaScript injection
541+
*
542+
* @param array $arguments
543+
* @return array
544+
*/
545+
protected function prepareScriptArguments(array $arguments)
546+
{
547+
$args = [];
548+
foreach ($arguments as $key => $value) {
549+
if ($value instanceof WebDriverElement) {
550+
$args[$key] = ['ELEMENT' => $value->getID()];
551+
} else {
552+
if (is_array($value)) {
553+
$value = $this->prepareScriptArguments($value);
554+
}
555+
$args[$key] = $value;
556+
}
557+
}
558+
559+
return $args;
560+
}
561+
562+
/**
563+
* @return RemoteExecuteMethod
564+
*/
565+
protected function getExecuteMethod()
566+
{
567+
if (!$this->executeMethod) {
568+
$this->executeMethod = new RemoteExecuteMethod($this);
569+
}
570+
571+
return $this->executeMethod;
572+
}
573+
574+
/**
575+
* Return the WebDriverElement with the given id.
576+
*
577+
* @param string $id The id of the element to be created.
578+
* @return RemoteWebElement
579+
*/
580+
protected function newElement($id)
581+
{
582+
return new RemoteWebElement($this->getExecuteMethod(), $id);
583+
}
584+
585+
/**
586+
* Cast legacy types (array or null) to DesiredCapabilities object. To be removed in future when instance of
587+
* DesiredCapabilities will be required.
588+
*
589+
* @param array|DesiredCapabilities|null $desired_capabilities
590+
* @return DesiredCapabilities
591+
*/
592+
protected static function castToDesiredCapabilitiesObject($desired_capabilities = null)
593+
{
594+
if ($desired_capabilities === null) {
595+
return new DesiredCapabilities();
596+
}
597+
598+
if (is_array($desired_capabilities)) {
599+
return new DesiredCapabilities($desired_capabilities);
600+
}
601+
602+
return $desired_capabilities;
603+
}
604604
}

lib/Remote/RemoteWebElement.php

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -342,42 +342,6 @@ public function sendKeys($value)
342342
return $this;
343343
}
344344

345-
/**
346-
* Upload a local file to the server
347-
*
348-
* @param string $local_file
349-
*
350-
* @throws WebDriverException
351-
* @return string The remote path of the file.
352-
*/
353-
private function upload($local_file)
354-
{
355-
if (!is_file($local_file)) {
356-
throw new WebDriverException('You may only upload files: ' . $local_file);
357-
}
358-
359-
// Create a temporary file in the system temp directory.
360-
$temp_zip = tempnam(sys_get_temp_dir(), 'WebDriverZip');
361-
$zip = new ZipArchive();
362-
if ($zip->open($temp_zip, ZipArchive::CREATE) !== true) {
363-
return false;
364-
}
365-
$info = pathinfo($local_file);
366-
$file_name = $info['basename'];
367-
$zip->addFile($local_file, $file_name);
368-
$zip->close();
369-
$params = [
370-
'file' => base64_encode(file_get_contents($temp_zip)),
371-
];
372-
$remote_path = $this->executor->execute(
373-
DriverCommand::UPLOAD_FILE,
374-
$params
375-
);
376-
unlink($temp_zip);
377-
378-
return $remote_path;
379-
}
380-
381345
/**
382346
* Set the fileDetector in order to let the RemoteWebElement to know that
383347
* you are going to upload a file.
@@ -450,4 +414,40 @@ protected function newElement($id)
450414
{
451415
return new static($this->executor, $id);
452416
}
417+
418+
/**
419+
* Upload a local file to the server
420+
*
421+
* @param string $local_file
422+
*
423+
* @throws WebDriverException
424+
* @return string The remote path of the file.
425+
*/
426+
protected function upload($local_file)
427+
{
428+
if (!is_file($local_file)) {
429+
throw new WebDriverException('You may only upload files: ' . $local_file);
430+
}
431+
432+
// Create a temporary file in the system temp directory.
433+
$temp_zip = tempnam(sys_get_temp_dir(), 'WebDriverZip');
434+
$zip = new ZipArchive();
435+
if ($zip->open($temp_zip, ZipArchive::CREATE) !== true) {
436+
return false;
437+
}
438+
$info = pathinfo($local_file);
439+
$file_name = $info['basename'];
440+
$zip->addFile($local_file, $file_name);
441+
$zip->close();
442+
$params = [
443+
'file' => base64_encode(file_get_contents($temp_zip)),
444+
];
445+
$remote_path = $this->executor->execute(
446+
DriverCommand::UPLOAD_FILE,
447+
$params
448+
);
449+
unlink($temp_zip);
450+
451+
return $remote_path;
452+
}
453453
}

lib/Support/Events/EventFiringWebDriver.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,6 @@ public function getDispatcher()
6060
return $this->dispatcher;
6161
}
6262

63-
/**
64-
* @param mixed $method
65-
*/
66-
protected function dispatch($method)
67-
{
68-
if (!$this->dispatcher) {
69-
return;
70-
}
71-
72-
$arguments = func_get_args();
73-
unset($arguments[0]);
74-
$this->dispatcher->dispatch($method, $arguments);
75-
}
76-
7763
/**
7864
* @return WebDriver
7965
*/
@@ -82,15 +68,6 @@ public function getWebDriver()
8268
return $this->driver;
8369
}
8470

85-
/**
86-
* @param WebDriverElement $element
87-
* @return EventFiringWebElement
88-
*/
89-
protected function newElement(WebDriverElement $element)
90-
{
91-
return new EventFiringWebElement($element, $this->getDispatcher());
92-
}
93-
9471
/**
9572
* @param mixed $url
9673
* @throws WebDriverException
@@ -408,10 +385,33 @@ public function execute($name, $params)
408385
}
409386
}
410387

388+
/**
389+
* @param WebDriverElement $element
390+
* @return EventFiringWebElement
391+
*/
392+
protected function newElement(WebDriverElement $element)
393+
{
394+
return new EventFiringWebElement($element, $this->getDispatcher());
395+
}
396+
397+
/**
398+
* @param mixed $method
399+
*/
400+
protected function dispatch($method)
401+
{
402+
if (!$this->dispatcher) {
403+
return;
404+
}
405+
406+
$arguments = func_get_args();
407+
unset($arguments[0]);
408+
$this->dispatcher->dispatch($method, $arguments);
409+
}
410+
411411
/**
412412
* @param WebDriverException $exception
413413
*/
414-
private function dispatchOnException(WebDriverException $exception)
414+
protected function dispatchOnException(WebDriverException $exception)
415415
{
416416
$this->dispatch('onException', $exception, $this);
417417
}

0 commit comments

Comments
 (0)