Skip to content

Commit 37092bd

Browse files
authored
Apply fixes from StyleCI (#11)
1 parent c98b34f commit 37092bd

16 files changed

+124
-116
lines changed

src/Code/Base.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace CodeDredd\Soap\Code;
34

45
use CodeDredd\Soap\Types\Service;
@@ -7,12 +8,10 @@
78
use Laminas\Code\Generator\FileGenerator;
89

910
/**
10-
* Class Base
11-
* @package CodeDredd\Soap\Code
11+
* Class Base.
1212
*/
1313
class Base
1414
{
15-
1615
/**
1716
* @var \Illuminate\Support\Collection
1817
*/
@@ -67,18 +66,20 @@ public function __construct(Service $engine, $configName)
6766
/**
6867
* @return string
6968
*/
70-
public function getCode() {
69+
public function getCode()
70+
{
7171
return $this->codeClass->generate();
7272
}
7373

7474
/**
7575
* @param $filePath
7676
*/
77-
public function saveFile($filePath) {
78-
$file = config('soap.code.path', app_path('Soap')) . $filePath;
79-
if (!file_exists($file)) {
77+
public function saveFile($filePath)
78+
{
79+
$file = config('soap.code.path', app_path('Soap')).$filePath;
80+
if (! file_exists($file)) {
8081
$fileCode = FileGenerator::fromArray([
81-
'classes' => [$this->codeClass]
82+
'classes' => [$this->codeClass],
8283
]);
8384
mkdir(dirname($file), 0777, true);
8485
file_put_contents($file, $fileCode->generate());

src/Code/Client.php

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace CodeDredd\Soap\Code;
34

45
use CodeDredd\Soap\Facades\Soap;
@@ -15,8 +16,7 @@
1516
use Wsdl2PhpGenerator\Operation;
1617

1718
/**
18-
* Class Client
19-
* @package CodeDredd\Soap\Code
19+
* Class Client.
2020
*/
2121
class Client extends Base
2222
{
@@ -48,45 +48,46 @@ public function createNewClient()
4848
$className = ucfirst(Str::camel($this->configName).'Client');
4949
$methodTags = $this->actions->map(function (Operation $action) {
5050
$params = $action->getParams() > 0 ? '($body = [])' : '()';
51+
5152
return new GenericTag(
5253
'method',
53-
'CodeDredd\\Soap\\Client\\Response ' . $action->getName() . $params
54+
'CodeDredd\\Soap\\Client\\Response '.$action->getName().$params
5455
);
5556
})->values()->toArray();
5657
$docBlock = DocBlockGenerator::fromArray([
5758
'shortDescription' => $this->clientClassName.' Client',
58-
'tags' => $methodTags
59+
'tags' => $methodTags,
5960
]);
6061
$constructorDocBlock = DocBlockGenerator::fromArray([
61-
'shortDescription' => $className.' constructor'
62+
'shortDescription' => $className.' constructor',
6263
]);
6364
$callDocBlock = DocBlockGenerator::fromArray([
6465
'shortDescription' => 'Execute soap call',
6566
'tags' => [
6667
new ParamTag('method', 'string'),
6768
new ParamTag('parameters', 'mixed'),
68-
new ReturnTag('\CodeDredd\Soap\Client\Response|mixed')
69-
]
69+
new ReturnTag('\CodeDredd\Soap\Client\Response|mixed'),
70+
],
7071
]);
7172
$callMethodParameters = [
7273
'method',
73-
'parameters'
74+
'parameters',
7475
];
7576
$callMethodBody = 'if (static::hasMacro($method)) {'."\n "
7677
.'return $this->macroCall($method, $parameters);'."\n"
7778
.'}'."\n\n"
78-
. '$validationClass = \'CodeDredd\\\\Soap\\\\Soap\\\\Validations\\\\LaravelSoap\\\\\''."\n "
79-
. '. ucfirst(Str::camel($method))'."\n "
80-
. '. \'Validation\';'."\n"
79+
.'$validationClass = \'CodeDredd\\\\Soap\\\\Soap\\\\Validations\\\\LaravelSoap\\\\\''."\n "
80+
.'. ucfirst(Str::camel($method))'."\n "
81+
.'. \'Validation\';'."\n"
8182
.'if (class_exists($validationClass)) {'."\n "
82-
. '$parameters = app()->call([$validationClass, \'validator\'], [\'parameters\' => $parameters]);'."\n"
83-
. '}'."\n\n"
83+
.'$parameters = app()->call([$validationClass, \'validator\'], [\'parameters\' => $parameters]);'."\n"
84+
.'}'."\n\n"
8485
.'return $this->client->call($method, $parameters);';
8586

8687
$this->codeClass->setName($className)
8788
->setDocBlock($docBlock)
88-
->setNamespaceName($this->codeNamespace . '\\Clients')
89-
->setImplementedInterfaces([$this->codeNamespace . '\\Contracts\\' . $this->clientClassName . 'Contract'])
89+
->setNamespaceName($this->codeNamespace.'\\Clients')
90+
->setImplementedInterfaces([$this->codeNamespace.'\\Contracts\\'.$this->clientClassName.'Contract'])
9091
->addProperty('client', null, PropertyGenerator::FLAG_PROTECTED)
9192
->addUse(Soap::class)
9293
->addUse(Macroable::class)
@@ -106,36 +107,38 @@ public function createNewClient()
106107
* @param Operation $action
107108
* @return MethodGenerator
108109
*/
109-
public static function createNewAction(Operation $action) {
110+
public static function createNewAction(Operation $action)
111+
{
110112
$validationClass = ucfirst(Str::camel($action->getName()).'Validation');
111-
$actionBody = 'return $this->client->call(\'' . $action->getName()
112-
. '\', ' . $validationClass . '::validator($body));';
113+
$actionBody = 'return $this->client->call(\''.$action->getName()
114+
.'\', '.$validationClass.'::validator($body));';
115+
113116
return new MethodGenerator(
114117
$action->getName(),
115118
empty($action->getParams()) ? [] : [
116119
[
117120
'name' => 'body',
118-
'defaultValue' => []
119-
]
121+
'defaultValue' => [],
122+
],
120123
],
121124
MethodGenerator::FLAG_PUBLIC,
122125
$actionBody,
123126
DocBlockGenerator::fromArray([
124-
'shortDescription' => 'Call action ' . $action->getName(),
127+
'shortDescription' => 'Call action '.$action->getName(),
125128
'tags' => [
126129
new ParamTag('body', 'array'),
127-
new ReturnTag('\CodeDredd\Soap\Client\Response')
128-
]
130+
new ReturnTag('\CodeDredd\Soap\Client\Response'),
131+
],
129132
])
130133
);
131134
}
132135

133136
/**
134-
* Save generated code as file
137+
* Save generated code as file.
135138
*/
136-
public function save() {
139+
public function save()
140+
{
137141
$this->clientContract->save();
138-
$this->saveFile('/Clients/' . $this->clientClassName .'Client.php');
142+
$this->saveFile('/Clients/'.$this->clientClassName.'Client.php');
139143
}
140-
141144
}

src/Code/ClientContract.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace CodeDredd\Soap\Code;
34

45
use CodeDredd\Soap\Types\Service;
@@ -9,8 +10,7 @@
910
use Wsdl2PhpGenerator\Operation;
1011

1112
/**
12-
* Class ClientContract
13-
* @package CodeDredd\Soap\Code
13+
* Class ClientContract.
1414
*/
1515
class ClientContract extends Base
1616
{
@@ -29,27 +29,31 @@ public function __construct(Service $engine, $configName)
2929
/**
3030
* @return InterfaceGenerator
3131
*/
32-
public function createNewClientContract() {
32+
public function createNewClientContract()
33+
{
3334
$className = ucfirst(Str::camel($this->configName).'Contract');
3435
$methodTags = $this->actions->map(function (Operation $action) {
3536
$params = $action->getParams() > 0 ? '($body = []) ' : '() ';
37+
3638
return new GenericTag(
3739
'method',
38-
'CodeDredd\\Soap\\Client\\Response ' . $action->getName() . $params . $action->getDescription()
40+
'CodeDredd\\Soap\\Client\\Response '.$action->getName().$params.$action->getDescription()
3941
);
4042
})->values()->toArray();
4143
$docBlock = DocBlockGenerator::fromArray([
4244
'shortDescription' => $this->clientClassName.' Contract',
43-
'tags' => $methodTags
45+
'tags' => $methodTags,
4446
]);
47+
4548
return $this->codeClass->setName($className)
4649
->setDocBlock($docBlock);
4750
}
4851

4952
/**
50-
* Save generated code as file
53+
* Save generated code as file.
5154
*/
52-
public function save() {
53-
$this->saveFile('/Contracts/' . $this->clientClassName .'Contract.php');
55+
public function save()
56+
{
57+
$this->saveFile('/Contracts/'.$this->clientClassName.'Contract.php');
5458
}
5559
}

src/Code/Validation.php

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace CodeDredd\Soap\Code;
34

45
use CodeDredd\Soap\Types\Service;
@@ -14,8 +15,7 @@
1415
use Wsdl2PhpGenerator\Variable;
1516

1617
/**
17-
* Class Validation
18-
* @package CodeDredd\Soap\Code
18+
* Class Validation.
1919
*/
2020
class Validation extends Base
2121
{
@@ -49,7 +49,7 @@ public function __construct(Service $engine, $configName, $dryRun = false)
4949
public function createNewValidation(Operation $action)
5050
{
5151
$this->actionName = $action->getName();
52-
$className = ucfirst(Str::camel($action->getName()) . 'Validation');
52+
$className = ucfirst(Str::camel($action->getName()).'Validation');
5353
$validationArray = [];
5454
if (count($action->getParams()) > 0) {
5555
foreach ($action->getParams() as $key => $param) {
@@ -62,18 +62,17 @@ public function createNewValidation(Operation $action)
6262
$validationArray[] = $validationForParam;
6363
}
6464
$validationArray = Arr::dot($validationArray);
65-
6665
}
6766
$validatorFlags = [MethodGenerator::FLAG_PUBLIC, MethodGenerator::FLAG_STATIC];
68-
$validatorBody = 'return Validator::make($parameters, [' . "\n"
69-
. $this->arrayToStringCode($validationArray)
70-
. ']);';
67+
$validatorBody = 'return Validator::make($parameters, ['."\n"
68+
.$this->arrayToStringCode($validationArray)
69+
.']);';
7170
$docBlock = DocBlockGenerator::fromArray([
7271
'shortDescription' => $this->actionName.' Validation',
73-
'longDescription' => $action->getDescription()
72+
'longDescription' => $action->getDescription(),
7473
]);
7574
$this->codeClass->setName($className)
76-
->setNamespaceName($this->codeNamespace . '\\Validations\\' . $this->clientClassName)
75+
->setNamespaceName($this->codeNamespace.'\\Validations\\'.$this->clientClassName)
7776
->setDocBlock($docBlock)
7877
->addUse(Validator::class)
7978
->addMethod('validator', ['parameters'], $validatorFlags, $validatorBody);
@@ -84,10 +83,11 @@ public function createNewValidation(Operation $action)
8483
/**
8584
* @param array $actionNames
8685
*/
87-
public function generateValidationFiles(array $actionNames = []) {
86+
public function generateValidationFiles(array $actionNames = [])
87+
{
8888
foreach ($actionNames as $actionName) {
8989
$action = $this->actions->get($actionName);
90-
if (!empty($action)) {
90+
if (! empty($action)) {
9191
$this->codeClass = $this->createNewValidation($action);
9292
$this->dryRun ? print_r($this->getCode()) : $this->save();
9393
}
@@ -98,13 +98,15 @@ public function generateValidationFiles(array $actionNames = []) {
9898
* @param array $array
9999
* @return string
100100
*/
101-
protected function arrayToStringCode(array $array) {
101+
protected function arrayToStringCode(array $array)
102+
{
102103
$stringCode = '';
103104
foreach ($array as $key => $value) {
104-
if (!empty($value)) {
105-
$stringCode .= " '" . $key . '\' => \'' . $value . "',\n";
105+
if (! empty($value)) {
106+
$stringCode .= " '".$key.'\' => \''.$value."',\n";
106107
}
107108
}
109+
108110
return $stringCode;
109111
}
110112

@@ -121,10 +123,10 @@ public function generateValidationArrayByAction(array $properties, $validationAr
121123
if ($propertyType instanceof ComplexType) {
122124
$validationArray['*'] = 'filled';
123125
$validationArray[$property->getName()] = $this->generateValidationArrayByAction($propertyType->getMembers());
124-
} elseif($propertyType instanceof Enum) {
125-
$validationArray[$property->getName()] = 'in:' . $propertyType->getValidValues();
126+
} elseif ($propertyType instanceof Enum) {
127+
$validationArray[$property->getName()] = 'in:'.$propertyType->getValidValues();
126128
} else {
127-
$validationArray[$property->getName()] = $this->mapToValidType($property->getType()) . ($property->getNullable() ? '|nullable' : '');
129+
$validationArray[$property->getName()] = $this->mapToValidType($property->getType()).($property->getNullable() ? '|nullable' : '');
128130
}
129131
}
130132

@@ -135,7 +137,8 @@ public function generateValidationArrayByAction(array $properties, $validationAr
135137
* @param $type
136138
* @return string
137139
*/
138-
public function mapToValidType($type) {
140+
public function mapToValidType($type)
141+
{
139142
switch ($type) {
140143
case 'datetime': return 'date_format:Y-m-d H:i:s';
141144
case 'date': return 'date';
@@ -152,17 +155,19 @@ public function mapToValidType($type) {
152155
/**
153156
* @return string
154157
*/
155-
public function getCode() {
158+
public function getCode()
159+
{
156160
return $this->codeClass->generate();
157161
}
158162

159163
/**
160-
* Save generated code as file
164+
* Save generated code as file.
161165
*/
162-
public function save() {
166+
public function save()
167+
{
163168
$this->saveFile(
164-
'/Validations/' . $this->clientClassName . '/'
165-
. ucfirst(Str::camel($this->actionName).'Validation.php')
169+
'/Validations/'.$this->clientClassName.'/'
170+
.ucfirst(Str::camel($this->actionName).'Validation.php')
166171
);
167172
}
168173
}

0 commit comments

Comments
 (0)