CompaniesGroupsMapper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 18
c 2
b 0
f 0
dl 0
loc 36
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A mapToObject() 0 28 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Mapper;
6
7
use AutoMapperPlus\CustomMapper\CustomMapper;
0 ignored issues
show
Bug introduced by
The type AutoMapperPlus\CustomMapper\CustomMapper 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...
8
use Canvas\Models\Subscription;
9
10
// You can either extend the CustomMapper, or just implement the MapperInterface
11
// directly.
12
class CompaniesGroupsMapper extends CustomMapper
13
{
14
    /**
15
     * @param Baka\Database\CustomFilters\CustomFilters $filter
0 ignored issues
show
Bug introduced by
The type Canvas\Mapper\Baka\Datab...omFilters\CustomFilters 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...
16
     * @param \Canvas\Dto\CustomFilter $filterSchema
17
     *
18
     * @return ListSchema
19
     */
20
    public function mapToObject($companiesGroup, $companiesGroupDto, array $context = [])
21
    {
22
        $companiesGroupDto->id = $companiesGroup->getId();
23
        $companiesGroupDto->name = $companiesGroup->name;
24
        $companiesGroupDto->users_id = $companiesGroup->users_id;
25
        $companiesGroupDto->apps_id = $companiesGroup->apps_id;
26
        $companyArray = [];
27
        /**
28
         * Let's find all companies and their apps plans.
29
         */
30
        foreach ($companiesGroup->getCompanies() as $company) {
31
            $subscription = Subscription::findFirst([
32
                'conditions' => 'user_id = ?0 and companies_id = ?1 and is_deleted = 0',
33
                'bind' => [$companiesGroup->users_id, $company->id]
34
            ]);
35
36
            foreach ($company as $key => $value) {
37
                $companyArray[$key] = $value;
38
                $companyArray['app_plan'] = $subscription->getAppPlan();
39
            }
40
41
            $companiesGroupDto->companies[] = $companyArray;
42
        }
43
        $companiesGroupDto->created_at = $companiesGroup->created_at;
44
        $companiesGroupDto->updated_at = $companiesGroup->updated_at;
45
        $companiesGroupDto->is_deleted = $companiesGroup->is_deleted;
46
47
        return $companiesGroupDto;
48
    }
49
}
50