Skip to content

Commit 9da3326

Browse files
authored
Merge pull request #56 from apisearch-io/feature/deleted-unused-code
Deleted unused code, added more tests
2 parents 9671d23 + f62de66 commit 9da3326

19 files changed

+3998
-1658
lines changed

.circleci/config.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ jobs:
1111
- run:
1212
name: Install PHPUnit
1313
command: |
14-
composer require phpunit/phpunit:7.*
14+
composer require phpunit/phpunit:7.5.17 --prefer-dist --prefer-stable --prefer-lowest --no-suggest
15+
16+
- run:
17+
name: Run tests / Symfony 3^3
18+
command: |
19+
php vendor/bin/phpunit
1520
1621
- run:
1722
name: Run tests / Symfony 4^3

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
vendor
2-
var
2+
var
3+
.php_cs.cache

.php_cs

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ return PhpCsFixer\Config::create()
1212
->setRules([
1313
'@PSR2' => true,
1414
'@Symfony' => true,
15+
'single_line_after_imports' => false,
16+
'no_superfluous_phpdoc_tags' => false,
17+
'single_line_throw' => false
1518
])
1619
->setFinder($finder)
1720
;

.php_cs.cache

-1
This file was deleted.

Command/ApisearchFormattedCommand.php

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
6161
}
6262

6363
self::finishCommand($stopwatch, $output);
64+
65+
return 0;
6466
}
6567

6668
/**

Command/ConfigureIndexCommand.php

+2-96
Original file line numberDiff line numberDiff line change
@@ -15,101 +15,17 @@
1515

1616
namespace Apisearch\Command;
1717

18-
use Apisearch\App\AppRepositoryBucket;
1918
use Apisearch\Config\Config;
2019
use Apisearch\Config\Synonym;
21-
use Apisearch\Config\SynonymReader;
2220
use Apisearch\Exception\ResourceNotAvailableException;
23-
use Symfony\Component\Console\Input\InputArgument;
2421
use Symfony\Component\Console\Input\InputInterface;
25-
use Symfony\Component\Console\Input\InputOption;
2622
use Symfony\Component\Console\Output\OutputInterface;
2723

2824
/**
2925
* Class ConfigureIndexCommand.
3026
*/
31-
class ConfigureIndexCommand extends WithAppRepositoryBucketCommand
27+
class ConfigureIndexCommand extends IndexBasedCommand
3228
{
33-
/**
34-
* @var SynonymReader
35-
*
36-
* Synonym Reader
37-
*/
38-
private $synonymReader;
39-
40-
/**
41-
* WithAppRepositoryBucketCommand constructor.
42-
*
43-
* @param AppRepositoryBucket $repositoryBucket
44-
* @param SynonymReader $synonymReader
45-
*/
46-
public function __construct(
47-
AppRepositoryBucket $repositoryBucket,
48-
SynonymReader $synonymReader
49-
) {
50-
parent::__construct($repositoryBucket);
51-
52-
$this->synonymReader = $synonymReader;
53-
}
54-
55-
/**
56-
* Configures the current command.
57-
*/
58-
protected function configure()
59-
{
60-
$this
61-
->setDescription('Configure an index')
62-
->addArgument(
63-
'app-name',
64-
InputArgument::REQUIRED,
65-
'App name'
66-
)
67-
->addArgument(
68-
'index-name',
69-
InputArgument::REQUIRED,
70-
'Index'
71-
)
72-
->addOption(
73-
'language',
74-
null,
75-
InputOption::VALUE_OPTIONAL,
76-
'Index language',
77-
null
78-
)
79-
->addOption(
80-
'no-store-searchable-metadata',
81-
null,
82-
InputOption::VALUE_NONE,
83-
'Store searchable metadata'
84-
)
85-
->addOption(
86-
'synonym',
87-
null,
88-
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
89-
'Synonym'
90-
)
91-
->addOption(
92-
'synonyms-file',
93-
null,
94-
InputOption::VALUE_OPTIONAL,
95-
'Synonyms file'
96-
)
97-
->addOption(
98-
'shards',
99-
null,
100-
InputOption::VALUE_OPTIONAL,
101-
'Shards for the index',
102-
Config::DEFAULT_SHARDS
103-
)
104-
->addOption(
105-
'replicas',
106-
null,
107-
InputOption::VALUE_OPTIONAL,
108-
'Replicas for the index',
109-
Config::DEFAULT_REPLICAS
110-
);
111-
}
112-
11329
/**
11430
* Dispatch domain event.
11531
*
@@ -122,17 +38,7 @@ protected function runCommand(InputInterface $input, OutputInterface $output)
12238
{
12339
$appName = $input->getArgument('app-name');
12440
list($_, $indexUUID) = $this->getRepositoryAndIndex($input, $output);
125-
$synonymsFile = $input->getOption('synonyms-file');
126-
127-
$synonyms = !is_null($synonymsFile)
128-
? $this
129-
->synonymReader
130-
->readSynonymsFromFile($input->getOption('synonyms-file'))
131-
: [];
132-
133-
$synonyms += $this
134-
->synonymReader
135-
->readSynonymsFromCommaSeparatedArray($input->getOption('synonym'));
41+
$synonyms = $this->loadSynonyms($input);
13642

13743
try {
13844
$this

Command/CreateIndexCommand.php

+2-96
Original file line numberDiff line numberDiff line change
@@ -15,101 +15,17 @@
1515

1616
namespace Apisearch\Command;
1717

18-
use Apisearch\App\AppRepositoryBucket;
1918
use Apisearch\Config\Config;
2019
use Apisearch\Config\Synonym;
21-
use Apisearch\Config\SynonymReader;
2220
use Apisearch\Exception\ResourceNotAvailableException;
23-
use Symfony\Component\Console\Input\InputArgument;
2421
use Symfony\Component\Console\Input\InputInterface;
25-
use Symfony\Component\Console\Input\InputOption;
2622
use Symfony\Component\Console\Output\OutputInterface;
2723

2824
/**
2925
* Class CreateIndexCommand.
3026
*/
31-
class CreateIndexCommand extends WithAppRepositoryBucketCommand
27+
class CreateIndexCommand extends IndexBasedCommand
3228
{
33-
/**
34-
* @var SynonymReader
35-
*
36-
* Synonym Reader
37-
*/
38-
private $synonymReader;
39-
40-
/**
41-
* WithAppRepositoryBucketCommand constructor.
42-
*
43-
* @param AppRepositoryBucket $repositoryBucket
44-
* @param SynonymReader $synonymReader
45-
*/
46-
public function __construct(
47-
AppRepositoryBucket $repositoryBucket,
48-
SynonymReader $synonymReader
49-
) {
50-
parent::__construct($repositoryBucket);
51-
52-
$this->synonymReader = $synonymReader;
53-
}
54-
55-
/**
56-
* Configures the current command.
57-
*/
58-
protected function configure()
59-
{
60-
$this
61-
->setDescription('Create an index')
62-
->addArgument(
63-
'app-name',
64-
InputArgument::REQUIRED,
65-
'App name'
66-
)
67-
->addArgument(
68-
'index-name',
69-
InputArgument::REQUIRED,
70-
'Index name'
71-
)
72-
->addOption(
73-
'language',
74-
null,
75-
InputOption::VALUE_OPTIONAL,
76-
'Index language',
77-
null
78-
)
79-
->addOption(
80-
'no-store-searchable-metadata',
81-
null,
82-
InputOption::VALUE_NONE,
83-
'Store searchable metadata'
84-
)
85-
->addOption(
86-
'synonym',
87-
null,
88-
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
89-
'Synonym'
90-
)
91-
->addOption(
92-
'synonyms-file',
93-
null,
94-
InputOption::VALUE_OPTIONAL,
95-
'Synonyms file'
96-
)
97-
->addOption(
98-
'shards',
99-
null,
100-
InputOption::VALUE_OPTIONAL,
101-
'Shards for the index',
102-
Config::DEFAULT_SHARDS
103-
)
104-
->addOption(
105-
'replicas',
106-
null,
107-
InputOption::VALUE_OPTIONAL,
108-
'Replicas for the index',
109-
Config::DEFAULT_REPLICAS
110-
);
111-
}
112-
11329
/**
11430
* Dispatch domain event.
11531
*
@@ -122,17 +38,7 @@ protected function runCommand(InputInterface $input, OutputInterface $output)
12238
{
12339
$appName = $input->getArgument('app-name');
12440
list($_, $indexUUID) = $this->getRepositoryAndIndex($input, $output);
125-
$synonymsFile = $input->getOption('synonyms-file');
126-
127-
$synonyms = !is_null($synonymsFile)
128-
? $this
129-
->synonymReader
130-
->readSynonymsFromFile($input->getOption('synonyms-file'))
131-
: [];
132-
133-
$synonyms += $this
134-
->synonymReader
135-
->readSynonymsFromCommaSeparatedArray($input->getOption('synonym'));
41+
$synonyms = $this->loadSynonyms($input);
13642

13743
try {
13844
$this

0 commit comments

Comments
 (0)