Completed
Push — master ( 150a3d...219536 )
by
unknown
04:07
created

AllFeeds::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 2
eloc 8
nc 2
nop 2
1
<?php
2
/**
3
 * ownCloud - News
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Bernhard Posselt <[email protected]>
9
 * @copyright Bernhard Posselt 2016
10
 */
11
12
namespace OCA\News\Command\Updater;
13
14
use Exception;
15
16
use Symfony\Component\Console\Command\Command;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Output\OutputInterface;
19
20
use OCA\News\Service\FeedService;
21
22
23
class AllFeeds extends Command {
24
    private $feedService;
25
26
    public function __construct(FeedService $feedService) {
27
        parent::__construct();
28
        $this->feedService = $feedService;
29
    }
30
31
    protected function configure() {
32
        $json = '{"feeds": [{"id": 39, "userId": "john"}, // etc ]}';
33
34
        $this->setName('news:updater:all-feeds')
35
            ->setDescription('Prints a JSON string which contains all feed ' .
36
                             'ids and user ids, e.g.: ' . $json);
37
    }
38
39
    protected function execute(InputInterface $input, OutputInterface $output) {
40
        $feeds = $this->feedService->findAllFromAllUsers();
41
        $result = ['feeds' => []];
42
43
        foreach ($feeds as $feed) {
44
            $result['feeds'][] = [
45
                'id' => $feed->getId(),
46
                'userId' => $feed->getUserId()
47
            ];
48
        }
49
50
        print(json_encode($result));
51
    }
52
53
}
54