• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

miaoxing / services / 6801533350

08 Nov 2023 04:34PM UTC coverage: 10.534% (-0.8%) from 11.327%
6801533350

push

github

twinh
ci: add PHP 8, remove PHP 7.2, 7.3

69 of 655 relevant lines covered (10.53%)

2.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Service/Status.php
1
<?php
2

3
namespace Miaoxing\Services\Service;
4

5
use Wei\Record;
6

7
/**
8
 * 状态
9
 */
10
class Status extends \Miaoxing\Plugin\BaseService
11
{
12
    /**
13
     * 根据模板创建一份新的状态配置,多出的状态会被移除
14
     *
15
     * @param array $allConfigs 所有的状态配置
16
     * @param array $tplConfigs 模板的状态配置
17
     * @return array
18
     */
19
    public function create(array $allConfigs, array $tplConfigs)
20
    {
21
        // tpl的值覆盖all的值
22
        return array_replace_recursive(
×
23
            array_intersect_key($allConfigs, $tplConfigs), // 剩下all的值
×
24
            array_intersect_key($tplConfigs, $allConfigs) // 剩下tpl的值
×
25
        );
×
26
    }
27

28
    /**
29
     * 根据模板创建一份新的状态配置,允许加入新的状态
30
     *
31
     * @param array $allConfigs
32
     * @param array $tplConfigs
33
     * @return array
34
     * @todo 待和create合并
35
     */
36
    public function createWithNewStatuses(array $allConfigs, array $tplConfigs)
37
    {
38
        return array_replace_recursive(
×
39
            array_intersect_key($allConfigs, $tplConfigs), // 剩下all的值
×
40
            $tplConfigs
×
41
        );
×
42
    }
43

44
    /**
45
     * 获取指定状态名称的配置,如果名称不存在,返回默认(未指定则第一个)配置
46
     *
47
     * @param string $reqStatus
48
     * @param array $configs
49
     * @param bool|false|int $defaultId 默认的状态,数字形式
50
     * @return mixed
51
     */
52
    public function req($reqStatus, array $configs, $defaultId = false)
53
    {
54
        $key = array_search($reqStatus, $this->coll->column($configs, 'name', 'id'), true);
×
55
        if (false === $key) {
×
56
            $key = $defaultId;
×
57
        }
58

59
        if (false === $key) {
×
60
            $config = current($configs);
×
61
        } else {
62
            $config = $configs[$key];
×
63
        }
64

65
        return $config['name'];
×
66
    }
67

68
    /**
69
     * 调用状态相应的方法
70
     *
71
     * @param Record $record
72
     * @param string $status
73
     * @return mixed
74
     */
75
    public function query($record, $status)
76
    {
77
        // 1. 触发自身的查询
78
        $method = lcfirst(str_replace('-', '', ucwords($status, '-')));
×
79
        if (method_exists($record, $method)) {
×
80
            $record->{$method}();
×
81
        }
82

83
        // 2. 触发事件查询
84
        $event = $record->getTable() . 'Query' . ucfirst($method);
×
85
        $this->event->trigger($event, [$record]);
×
86
    }
87
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc