Completed
Push — add/monorepo-docs ( 676d5e...42d969 )
by
unknown
26:32 queued 16:26
created

CoreCalls::callback()   B

Complexity

Conditions 7
Paths 48

Size

Total Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
nc 48
nop 1
dl 0
loc 38
rs 8.3786
c 0
b 0
f 0
1
<?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
/**
3
 * Function call finder script.
4
 *
5
 * @package automattic/jetpack-analyzer
6
 */
7
8
namespace Automattic\Jetpack\Analyzer;
9
10
use Composer\Script\Event;
11
12
/**
13
 * This class holds the callback for the WordPress API function analyzer.
14
 */
15
class CoreCalls {
16
17
	/**
18
	 * A static method to handle the Composer script call that
19
	 * triggers a repository code scan for WordPress Core function
20
	 * calls.
21
	 *
22
	 * @param Composer\Script\Event $event a script call event.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $event not be Event?

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...
23
	 */
24
	public static function callback( Event $event ) {
25
		$arguments = $event->getArguments();
26
		$scan_path = isset( $arguments[0] ) ? $arguments[0] : null;
27
		$core_path = isset( $arguments[1] ) ? $arguments[1] : null;
28
		$io        = $event->getIO();
29
30
		if (
31
			is_null( $scan_path )
32
			|| is_null( $core_path )
33
		) {
34
			$io->writeError( 'Scan path and WordPress Core source paths are required for this script to work.' );
35
			$io->writeError( 'Usage: composer run core-calls /path/to/plugin /path/to/wordpress/src' );
36
			return;
37
		}
38
39
		try {
40
			$declarations = CoreDefinitions::get_declarations( $core_path );
41
42
			$invocations = new Invocations();
43
			$invocations->scan( $scan_path, array( 'vendor', 'vendor_prefixed' ) );
44
45
			$dependencies = new Dependencies();
46
			$dependencies->generate( $invocations, $declarations );
47
			foreach ( $dependencies->get() as $dependency ) {
48
49
				$io->write(
50
					$dependency->invocation->display_name() . ', ' .
51
					$dependency->invocation->path . ', ' .
52
					$dependency->invocation->line
53
				);
54
55
			}
56
		} catch ( Exception $e ) {
0 ignored issues
show
Bug introduced by
The class Automattic\Jetpack\Analyzer\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
57
			$io->writeError( 'Exception caught' );
58
			$io->writeError( $e->getMessage() );
59
			return;
60
		}
61
	}
62
}
63