Skip to content

Commit 9c7085b

Browse files
committed
fixed scrutinizer issues
1 parent 6b97c3a commit 9c7085b

10 files changed

Lines changed: 100 additions & 124 deletions

File tree

peridot.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
use Peridot\Plugin\Prophecy\ProphecyPlugin;
44

55
return function (EventEmitterInterface $emitter) {
6-
$plugin = new ProphecyPlugin($emitter);
6+
new ProphecyPlugin($emitter);
77
};

src/Application/BaseApplication.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ public function after()
4949
return;
5050
}
5151

52-
protected function getArguments($request, $response, $data)
53-
{
54-
return [];
55-
}
52+
abstract protected function getArguments($request, $response, $data);
5653
/**
5754
* @return RouterInterface
5855
*/

src/Application/HTTP/App.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Command\ErrorCommand;
88
use DI\Container;
99
use Application\BaseApplication;
10+
use Psr\Log\LoggerInterface;
1011
use Symfony\Component\EventDispatcher\EventDispatcher;
1112

1213
class App extends BaseApplication
@@ -43,6 +44,8 @@ protected function setResponseHeaders($response)
4344
'Origin' => 'http://localhost:15155'
4445
]);
4546
} catch (\Exception $e) {
47+
$this->container->get(LoggerInterface::class)
48+
->addDebug("Response writing failed");
4649
}
4750
}
4851
protected function parseQuery(array $query, $data)

src/Command/GenerateCommand.php

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,26 @@
44

55
use Entity\Project;
66

7-
class GenerateCommand extends AbstractCommand{
8-
public function run(array $arguments = []){
9-
$time = microtime(true);
10-
$verbose = $this->isVerbose($arguments);
7+
class GenerateCommand extends AbstractCommand
8+
{
9+
public function run(array $arguments = [])
10+
{
1111
$generator = $this->get("Generator\IndexGenerator");
1212
$rootDir = getcwd();
13-
if(array_key_exists("rootDir", $arguments)){
13+
if (array_key_exists("rootDir", $arguments)) {
1414
$rootDir = $arguments["rootDir"];
1515
}
1616
$project = new Project(
1717
$this->get("Entity\Index"),
1818
$rootDir
1919
);
2020

21-
$index = $generator->generateIndex($project);
21+
$generator->generateIndex($project);
2222
$indexWriter = $this->get('IO\Writer');
2323

2424
$indexWriter->write($project);
2525
return [
2626
"status" => "ok"
2727
];
2828
}
29-
protected function printJsonError($errorCode)
30-
{
31-
switch (json_last_error()) {
32-
case JSON_ERROR_NONE:
33-
echo ' - No errors';
34-
break;
35-
case JSON_ERROR_DEPTH:
36-
echo ' - Maximum stack depth exceeded';
37-
break;
38-
case JSON_ERROR_STATE_MISMATCH:
39-
echo ' - Underflow or the modes mismatch';
40-
break;
41-
case JSON_ERROR_CTRL_CHAR:
42-
echo ' - Unexpected control character found';
43-
break;
44-
case JSON_ERROR_SYNTAX:
45-
echo ' - Syntax error, malformed JSON';
46-
break;
47-
case JSON_ERROR_UTF8:
48-
echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
49-
break;
50-
default:
51-
echo ' - Unknown error';
52-
break;
53-
}
54-
echo "\n";
55-
}
5629
}

src/Command/KillCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class KillCommand implements CommandInterface
66
{
7-
public function run()
7+
public function run(array $arguments = [])
88
{
99
die();
1010
}

src/Command/PluginCommand.php

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,20 @@ public function run(array $arguments = [])
88
{
99
$commandName = array_shift($arguments);
1010
$pluginName = array_shift($arguments);
11-
if ($commandName === 'add') {
12-
return $this->addAction($pluginName);
13-
} elseif ($commandName === 'remove') {
14-
return $this->removeAction($pluginName);
15-
}
16-
}
17-
public function addAction($pluginName)
18-
{
19-
/** @var \Plugin\Package */
20-
$package = $this->getContainer()->get("Plugin\\Package");
21-
$plugins = $package->getPluginsList();
22-
if (array_key_exists($pluginName, $plugins)) {
23-
return;
24-
}
25-
$plugins[] = $pluginName;
26-
$package->writePluginsList($plugins);
27-
}
28-
public function removeAction($pluginName)
29-
{
3011
/** @var \Plugin\Package */
3112
$package = $this->getContainer()->get("Plugin\\Package");
3213
$plugins = $package->getPluginsList();
33-
if (!array_key_exists($pluginName, $plugins)) {
34-
return;
14+
if ($commandName === 'add') {
15+
if (array_key_exists($pluginName, $plugins)) {
16+
return;
17+
}
18+
$plugins[] = $pluginName;
19+
} elseif ($commandName === 'remove') {
20+
if (!array_key_exists($pluginName, $plugins)) {
21+
return;
22+
}
23+
unset($plugins[$pluginName]);
3524
}
36-
unset($plugins[$pluginName]);
3725
$package->writePluginsList($plugins);
3826
}
3927
}

src/Complete/CompleteEngine.php

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,30 @@ public function createCompletion(
4646
){
4747
$start = microtime(1);
4848
$entries = [];
49-
if($line){
50-
list($lines, $badLine, $completionLine) = $this->prepareContent(
49+
if ($line) {
50+
list($lines, , $completionLine) = $this->prepareContent(
5151
$content,
5252
$line,
5353
$column
5454
);
5555
try {
5656
$scope = $this->processFileContent($project, $lines, $line, $file);
57-
if(empty($scope)){
57+
if (empty($scope)) {
5858
$scope = new Scope;
5959
}
60-
$this->logger->addDebug(sprintf(
61-
"%s seconds for ast processing"
62-
, (microtime(1) - $start)));
63-
}
64-
catch(\Exception $e){
60+
$this->logger->debug(sprintf(
61+
"%s seconds for ast processing",
62+
(microtime(1) - $start)
63+
));
64+
} catch (\Exception $e) {
6565
$scope = new Scope;
6666
}
67-
$entries = $this->findEntries($project, $scope, $completionLine, $column, $lines);
68-
$this->logger->addDebug(sprintf(
69-
"%s seconds for entries generation"
70-
, (microtime(1) - $start)));
71-
}
72-
elseif(!empty($content)) {
67+
$entries = $this->findEntries($project, $scope, $completionLine, $column);
68+
$this->logger->debug(sprintf(
69+
"%s seconds for entries generation",
70+
(microtime(1) - $start)
71+
));
72+
} elseif (!empty($content)) {
7373
$this->processFileContent($project, $content, $line, $file);
7474
}
7575

@@ -78,7 +78,8 @@ public function createCompletion(
7878
"context" => []
7979
];
8080
}
81-
protected function findEntries(Project $project, Scope $scope, $badLine, $column, $lines){
81+
protected function findEntries(Project $project, Scope $scope, $badLine, $column)
82+
{
8283
$context = $this->contextResolver->getContext($badLine, $project->getIndex(), $scope);
8384
$completer = $this->completerFactory->getCompleter($context, $project);
8485
if ($completer) {
@@ -92,10 +93,9 @@ protected function findEntries(Project $project, Scope $scope, $badLine, $column
9293
*/
9394
protected function prepareContent($content, $line, $column){
9495
$lines = explode(PHP_EOL, $content);
95-
if($line > count($lines)){
96+
if ($line > count($lines)) {
9697
$badLine = "";
97-
}
98-
else{
98+
} else {
9999
$badLine = $lines[$line-1];
100100
}
101101
$completionLine = substr($badLine, 0, $column-1);
@@ -107,26 +107,21 @@ protected function prepareContent($content, $line, $column){
107107
* @return Scope
108108
*/
109109
protected function processFileContent(Project $project, $lines, $line, $file){
110-
if(is_array($lines)){
110+
if (is_array($lines)) {
111111
$content = implode("\n", $lines);
112-
}
113-
else {
112+
} else {
114113
$content = $lines;
115114
}
116-
if(empty($content)){
115+
if (empty($content)) {
117116
return;
118117
}
119-
$fqcn = $project->getIndex()->findFQCNByFile($file);
120-
if (!$fqcn instanceof FQN) {
121-
$fqcn = new FQN();
122-
}
123118
if (!array_key_exists($file, $this->cachePool)) {
124119
$this->cachePool[$file] = [0, [], []];
125120
}
126-
if($this->isValidCache($file, $content)){
127-
list($hash, $indexNodes, $scopeNodes) = $this->cachePool[$file];
121+
if ($this->isValidCache($file, $content)) {
122+
list(,, $scopeNodes) = $this->cachePool[$file];
128123
}
129-
if(empty($scopeNodes)) {
124+
if (empty($scopeNodes)) {
130125
$this->indexProcessor->clearResultNodes();
131126
$parser = $this->parser;
132127
$parser->addProcessor($this->indexProcessor);
@@ -145,13 +140,14 @@ protected function processFileContent(Project $project, $lines, $line, $file){
145140
$contentHash = hash('sha1', $content);
146141
$this->cachePool[$file] = [$contentHash, $nodes, $scopeNodes];
147142
}
148-
if(count($scopeNodes)){
143+
if (count($scopeNodes)) {
149144
return $scopeNodes[0];
150145
}
151146
return null;
152147
}
153148

154-
private function isValidCache($file, $content){
149+
private function isValidCache($file, $content)
150+
{
155151
$contentHash = hash('sha1', $content);
156152
list($hash) = $this->cachePool[$file];
157153
return $hash === $contentHash;

src/Complete/Completer/ObjectCompleter.php

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,42 @@
1313
use Entity\Collection\Specification;
1414
use Psr\Log\LoggerInterface;
1515

16-
class ObjectCompleter {
17-
public function __construct(LoggerInterface $logger){
16+
class ObjectCompleter
17+
{
18+
public function __construct(LoggerInterface $logger)
19+
{
1820
$this->logger = $logger;
1921
}
20-
public function getEntries(Project $project, Context $context){
22+
public function getEntries(Project $project, Context $context)
23+
{
2124
/** @var FQCN $fqcn */
2225
list($fqcn, $isThis) = $context->getData();
23-
$this->logger->addDebug('creating entries');
24-
if(!$fqcn instanceof FQCN){
26+
$this->logger->debug('creating entries');
27+
if (!$fqcn instanceof FQCN) {
2528
return [];
2629
}
2730
$index = $project->getIndex();
28-
$this->logger->addDebug('Creating completion for ' . $fqcn->toString());
31+
$this->logger->debug('Creating completion for ' . $fqcn->toString());
2932
$class = $index->findClassByFQCN($fqcn);
30-
if(empty($class)){
33+
if (empty($class)) {
3134
$class = $index->findInterfaceByFQCN($fqcn);
3235
}
33-
if(empty($class)){
36+
if (empty($class)) {
3437
return [];
3538
}
3639
$entries = [];
3740
$spec = new Specification($isThis ? 'private' : 'public');
38-
if($class->methods !== null){
39-
foreach($class->methods->all($spec) AS $method){
41+
if ($class->methods !== null) {
42+
foreach ($class->methods->all($spec) as $method) {
4043
$entry = $this->createEntryForMethod($method);
4144
$entries[$method->name] = $entry;
4245
}
4346
}
44-
if($class instanceof InterfaceData){
47+
if ($class instanceof InterfaceData) {
4548
return $entries;
4649
}
47-
if($class->properties !== null){
48-
foreach($class->properties->all($spec) AS $property){
50+
if ($class->properties !== null) {
51+
foreach ($class->properties->all($spec) as $property) {
4952
$entries[$property->name] = $this->createEntryForProperty($property);
5053
}
5154
}
@@ -59,15 +62,17 @@ public function getEntries(Project $project, Context $context){
5962
* @param MethodData $method a method
6063
* @return Entry
6164
*/
62-
protected function createEntryForMethod(MethodData $method){
65+
protected function createEntryForMethod(MethodData $method)
66+
{
6367
return new Entry(
6468
$method->name,
6569
$method->getSignature(),
6670
sprintf("%s\n%s\n", $method->getSignature(), $method->doc)
6771
);
6872
}
6973

70-
protected function createEntryForProperty(ClassProperty $prop){
74+
protected function createEntryForProperty(ClassProperty $prop)
75+
{
7176
$type = $prop->type instanceof FQCN ? $prop->type->getClassName() : 'mixed';
7277
return new Entry(
7378
$prop->name,

0 commit comments

Comments
 (0)