Completed
Push — master ( bedd0e...7ec89a )
by Aimeos
08:44
created

lib/mwlib/src/MW/Process/Decorator/Check.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017
6
 * @package MW
7
 * @subpackage Process
8
 */
9
10
11
namespace Aimeos\MW\Process\Decorator;
12
13
14
/**
15
 * Check avaiability of parallel processing
16
 *
17
 * If not available, execute the tasks one after another
18
 *
19
 * @package MW
20
 * @subpackage Process
21
 */
22
class Check implements Iface
23
{
24
	private $object;
25
26
27
	/**
28
	 * Initializes the object
29
	 *
30
	 * @param Aimeos\MW\Process\Iface $object Parallel processing object
0 ignored issues
show
Should the type for parameter $object not be \Aimeos\MW\Process\Iface?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
31
	 */
32
	public function __construct( \Aimeos\MW\Process\Iface $object )
33
	{
34
		$this->object = $object;
35
	}
36
37
38
	/**
39
	 * Checks if processing tasks in parallel is available
40
	 *
41
	 * @return boolean True if available, false if not
42
	 */
43
	public function isAvailable()
44
	{
45
		return $this->object->isAvailable();
46
	}
47
48
49
	/**
50
	 * Starts a new task by executing the given anonymous function
51
	 *
52
	 * @param \Closure $fcn Anonymous function to execute
53
	 * @param array $data List of parameters that is passed to the closure function
54
	 * @param boolean $restart True if the task should be restarted if it fails (only once)
55
	 * @return void
0 ignored issues
show
Should the return type not be Check?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
56
	 * @throws \Aimeos\MW\Process\Exception If starting the new task failed
57
	 */
58
	public function start( \Closure $fcn, array $data, $restart = false )
59
	{
60
		if( $this->object->isAvailable() === true ) {
61
			$this->object->start( $fcn, $data, $restart );
62
		} else {
63
			call_user_func_array( $fcn, $data );
64
		}
65
66
		return $this;
67
	}
68
69
70
	/**
71
	 * Waits for the running tasks until all have finished
72
	 *
73
	 * @return void
0 ignored issues
show
Should the return type not be Check?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
74
	 */
75
	public function wait()
76
	{
77
		if( $this->object->isAvailable() === true ) {
78
			$this->object->wait();
79
		}
80
81
		return $this;
82
	}
83
}