NotificationManager   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
c 0
b 0
f 0
dl 0
loc 41
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A triggerNotification() 0 16 1
A __construct() 0 7 1
1
<?php
2
/**
3
 * Analytics
4
 *
5
 * SPDX-FileCopyrightText: 2019-2022 Marcel Scherello
6
 * SPDX-License-Identifier: AGPL-3.0-or-later
7
 */
8
9
namespace OCA\Analytics\Notification;
10
11
use OCP\Notification\IManager as INotificationManager;
0 ignored issues
show
Bug introduced by
The type OCP\Notification\IManager 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...
12
use Psr\Log\LoggerInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Log\LoggerInterface 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...
13
14
class NotificationManager
15
{
16
    const OBJECT_REPORT = 'analytics_report';
17
    const SUBJECT_THRESHOLD = 'data_threshold';
18
    const DATALOAD_ERROR = 'dataload_error';
19
    /** @var INotificationManager */
20
    protected $notificationManager;
21
    private $logger;
22
23
    public function __construct(
24
        LoggerInterface      $logger,
25
        INotificationManager $notificationManager
26
    )
27
    {
28
        $this->logger = $logger;
29
        $this->notificationManager = $notificationManager;
30
    }
31
32
    /**
33
     * @param string $object_type
34
     * @param int $object_id
35
     * @param $subject
36
     * @param array $subject_parameter
37
     * @param $user_id
38
     */
39
    public function triggerNotification($object_type, $object_id, $subject, $subject_parameter, $user_id)
40
    {
41
        $notification = $this->notificationManager->createNotification();
42
        $notification->setApp('analytics')
43
            ->setObject($object_type, $object_id)
44
            ->setSubject($subject)
45
            ->setUser($user_id);
46
        $this->notificationManager->markProcessed($notification);
47
48
        $notification = $this->notificationManager->createNotification();
49
        $notification->setApp('analytics')
50
            ->setDateTime(new \DateTime())
51
            ->setObject($object_type, $object_id)
52
            ->setSubject($subject, $subject_parameter)
53
            ->setUser($user_id);
54
        $this->notificationManager->notify($notification);
55
    }
56
}