Completed
Push — master ( 002107...b9ca83 )
by Carlos
02:53
created

Factory::work()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 0
cts 3
cp 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the overtrue/wechat.
5
 *
6
 * (c) overtrue <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace EasyWeChat;
13
14
/**
15
 * Class Factory.
16
 *
17
 * @method static \EasyWeChat\Payment\Application            payment(array $config)
18
 * @method static \EasyWeChat\MiniProgram\Application        miniProgram(array $config)
19
 * @method static \EasyWeChat\OpenPlatform\Application       openPlatform(array $config)
20
 * @method static \EasyWeChat\OfficialAccount\Application    officialAccount(array $config)
21
 * @method static \EasyWeChat\BasicService\Application       basicService(array $config)
22
 * @method static \EasyWeChat\Work\Application               work(array $config)
23
 */
24
class Factory
25
{
26
    /**
27
     * @param string $name
28
     * @param array  $config
29
     *
30
     * @return \EasyWeChat\Kernel\ServiceContainer|\EasyWeChat\Work\AgentFactory
0 ignored issues
show
Bug introduced by
The type EasyWeChat\Work\AgentFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
     */
32
    public static function make($name, array $config)
33
    {
34
        $namespace = Kernel\Support\Str::studly($name);
1 ignored issue
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
35
        $application = "\\EasyWeChat\\{$namespace}\\Application";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $namespace instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
36
37
        return new $application($config);
38
    }
39
40
    /**
41
     * Dynamically pass methods to the application.
42
     *
43
     * @param string $name
44
     * @param array  $arguments
45
     *
46
     * @return mixed
47
     */
48
    public static function __callStatic($name, $arguments)
49
    {
50
        return self::make($name, ...$arguments);
0 ignored issues
show
Bug introduced by
$arguments is expanded, but the parameter $config of EasyWeChat\Factory::make() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

50
        return self::make($name, /** @scrutinizer ignore-type */ ...$arguments);
Loading history...
51
    }
52
}
53