Completed
Push — master ( 43030a...db557c )
by Maxence
06:50 queued 04:30
created

DocumentPlatform   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 12.7 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 8
loc 63
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 8 8 1
A execute() 0 16 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * FullTextSearch - Full text search framework for Nextcloud
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2018
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\FullTextSearch\Command;
28
29
use Exception;
30
use OCA\FullTextSearch\Model\ExtendedBase;
31
use OCA\FullTextSearch\Service\MiscService;
32
use OCA\FullTextSearch\Service\PlatformService;
33
use Symfony\Component\Console\Input\InputArgument;
34
use Symfony\Component\Console\Input\InputInterface;
35
use Symfony\Component\Console\Input\InputOption;
36
use Symfony\Component\Console\Output\OutputInterface;
37
38
39
class DocumentPlatform extends ExtendedBase {
40
41
42
	/** @var PlatformService */
43
	private $platformService;
44
45
	/** @var MiscService */
46
	private $miscService;
47
48
49
	/**
50
	 * Index constructor.
51
	 *
52
	 * @param PlatformService $providerService
53
	 * @param MiscService $miscService
54
	 */
55
	public function __construct(PlatformService $providerService, MiscService $miscService) {
56
		parent::__construct();
57
58
		$this->platformService = $providerService;
59
		$this->miscService = $miscService;
60
	}
61
62
63
	/**
64
	 *
65
	 */
66 View Code Duplication
	protected function configure() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
		parent::configure();
68
		$this->setName('fulltextsearch:document:platform')
69
			 ->setDescription('Get document from index')
70
			 ->addArgument('providerId', InputArgument::REQUIRED, 'providerId')
71
			 ->addArgument('documentId', InputArgument::REQUIRED, 'documentId')
72
			 ->addOption('content', 'c', InputOption::VALUE_NONE, 'return some content');
73
	}
74
75
76
	/**
77
	 * @param InputInterface $input
78
	 * @param OutputInterface $output
79
	 *
80
	 * @return int|null|void
81
	 * @throws Exception
82
	 */
83
	protected function execute(InputInterface $input, OutputInterface $output) {
84
		$providerId = $input->getArgument('providerId');
85
		$documentId = $input->getArgument('documentId');
86
87
		$platform = $this->platformService->getPlatform();
88
89
		$indexDocument = $platform->getDocument($providerId, $documentId);
0 ignored issues
show
Bug introduced by
The method getDocument() does not seem to exist on object<OCA\FullTextSearc...FullTextSearchPlatform>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
90
		$result = [
91
			'document' => $indexDocument
92
		];
93
		if ($input->getOption('content') === true) {
94
			$result['content'] = substr($indexDocument->getContent(), 0, 200);
95
		}
96
97
		$output->writeln(json_encode($result, JSON_PRETTY_PRINT));
98
	}
99
100
101
}
102
103
104
105