Skip to content

Commit bec71e2

Browse files
committed
Code cleanup and delete returns true on any 200 status
1 parent 12c4e13 commit bec71e2

File tree

6 files changed

+30
-26
lines changed

6 files changed

+30
-26
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
return $config->setFinder(PhpCsFixer\Finder::create()
1212
->exclude('vendor')
1313
->in(__DIR__.'\src')
14-
->in(__DIR__.'\Tools')
14+
->in(__DIR__.'\Tool')
1515
->in(__DIR__.'\tests')
1616
);

Tests/CustomFieldTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,4 @@ public function testMaxLength() : void
7676
$this->expectException(\PHPFUI\ConstantContact\Exception\InvalidLength::class);
7777
$fixture->cf_string = \str_pad('', 300);
7878
}
79-
8079
}

Tests/DefinitionTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,5 +256,4 @@ public function testClassArraySizeMin() : void
256256
$this->assertIsArray($fixture->classArraySizeMin);
257257
$this->assertCount(2, $fixture->classArraySizeMin);
258258
}
259-
260259
}

Tool/Generator.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ public function makeDefinitions(array $definitions) : void
8080

8181
public function generateDefinition(string $namespacedClass, array $properties) : void
8282
{
83-
$parts = explode('\\', $namespacedClass);
84-
$class = array_pop($parts);
85-
$namespace = implode('\\', $parts);
83+
$parts = \explode('\\', $namespacedClass);
84+
$class = \array_pop($parts);
85+
$namespace = \implode('\\', $parts);
8686
$originalType = '';
8787

8888
if (! isset($properties['type']))
@@ -180,6 +180,7 @@ public function generateDefinition(string $namespacedClass, array $properties) :
180180
}
181181

182182
$description = '';
183+
183184
if (isset($details['description']))
184185
{
185186
$description = $this->cleanDescription(\trim($details['description']));
@@ -190,7 +191,7 @@ public function generateDefinition(string $namespacedClass, array $properties) :
190191
$type = $originalType;
191192
}
192193
$type = \str_replace('\\\\', '\\', $type);
193-
$docBlock[] = trim("{$type} {$dollar}{$name} {$description}");
194+
$docBlock[] = \trim("{$type} {$dollar}{$name} {$description}");
194195
}
195196
$this->generateFromTemplate($class, ['fields' => $fields, 'minLength' => $minLength, 'maxLength' => $maxLength, ], $docBlock);
196197
}
@@ -203,8 +204,9 @@ public function generateDefinition(string $namespacedClass, array $properties) :
203204
*/
204205
private function getUniqueClassName(string $namespace, string $class) : string
205206
{
206-
$namespace = trim($namespace, '\\');
207+
$namespace = \trim($namespace, '\\');
207208
$class = $this->getClassName($class);
209+
208210
if (isset($this->duplicateClasses[$class]))
209211
{
210212
$class = $this->duplicateClasses[$class];
@@ -217,7 +219,7 @@ private function getUniqueClassName(string $namespace, string $class) : string
217219
$fullName = '\\' . $namespace . '\\' . $class;
218220

219221
// if we have seen this class before, then it is the plural version and it should be singular because CC does not know how to design an API (among other things).
220-
if (! str_contains($fullName, 'Definition') && isset($this->generatedClasses[$fullName]))
222+
if (! \str_contains($fullName, 'Definition') && isset($this->generatedClasses[$fullName]))
221223
{
222224
if (\str_ends_with($class, 'ies'))
223225
{
@@ -238,9 +240,9 @@ private function getUniqueClassName(string $namespace, string $class) : string
238240

239241
private function writeClass(string $namespacedClass, string $apiPath, array $properties) : void
240242
{
241-
$parts = explode('\\', $namespacedClass);
242-
$class = array_pop($parts);
243-
$namespace = trim(implode('\\', $parts), '\\');
243+
$parts = \explode('\\', $namespacedClass);
244+
$class = \array_pop($parts);
245+
$namespace = \trim(\implode('\\', $parts), '\\');
244246

245247
$methods = '';
246248
$dollar = '$';
@@ -499,7 +501,7 @@ private function formatDescription(string $description) : string
499501
*/
500502
private function generateFromTemplate(string $name, array $properties, array $docBlocks) : void
501503
{
502-
$namespace = trim($this->definitionNamespace, '\\');
504+
$namespace = \trim($this->definitionNamespace, '\\');
503505

504506
$template = <<<PHP
505507
<?php
@@ -588,21 +590,21 @@ private function deleteFileTree(string $path) : void
588590
$directory = __DIR__ . '/../src/ConstantContact' . $path;
589591

590592
$iterator = new \RecursiveIteratorIterator(
591-
new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::SKIP_DOTS),
592-
\RecursiveIteratorIterator::SELF_FIRST);
593+
new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::SKIP_DOTS),
594+
\RecursiveIteratorIterator::SELF_FIRST
595+
);
593596

594597
foreach ($iterator as $item)
595598
{
596599
if (! $item->isDir())
597600
{
598601
$fileName = "{$item}";
599602
// don't delete base classes
600-
if (! str_ends_with($fileName, 'Base.php'))
603+
if (! \str_ends_with($fileName, 'Base.php'))
601604
{
602-
unlink($fileName);
605+
\unlink($fileName);
603606
}
604607
}
605608
}
606609
}
607-
608610
}

src/ConstantContact/Client.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ public function __construct(private string $clientAPIKey, private string $client
5757
*
5858
* Callback function signature:
5959
*
60-
* @param string $key used to store or retrieve $value
61-
* @param ?string $value if null, value should be returned and key deleted, if not null, value should be stored by key.
6260
* @return string $value from store or value passed in on set (ignored)
6361
*/
6462
public function setSessionCallback(callable $callback) : self
@@ -310,7 +308,7 @@ public function delete(string $url) : bool
310308

311309
$this->process($response);
312310

313-
return 204 == $this->statusCode;
311+
return $this->statusCode >= 200 && $this->statusCode < 300;
314312
}
315313
catch (\GuzzleHttp\Exception\RequestException $e)
316314
{
@@ -491,8 +489,9 @@ private function session(string $key, ?string $value) : string
491489
{
492490
if ($this->sessionCallback)
493491
{
494-
return call_user_func($this->sessionCallback, $key, $value);
492+
return \call_user_func($this->sessionCallback, $key, $value);
495493
}
494+
496495
if (null === $value)
497496
{
498497
$value = $_SESSION[$key];

src/ConstantContact/Definition/Base.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ public function __construct(array $initialValues = [])
5454
foreach ($initialValues as $field => $value)
5555
{
5656
$actualField = $field;
57-
if (str_starts_with($field, 'cf_'))
57+
58+
if (\str_starts_with($field, 'cf_'))
5859
{
5960
$field = 'cf:custom_field_name';
6061
}
6162
$type = static::$fields[$field] ?? null;
63+
6264
if (! $type)
6365
{
6466
continue;
@@ -88,10 +90,12 @@ public function __construct(array $initialValues = [])
8890
public function __get(string $field) : mixed
8991
{
9092
$actualField = $field;
91-
if (str_starts_with($field, 'cf_'))
93+
94+
if (\str_starts_with($field, 'cf_'))
9295
{
9396
$field = 'cf:custom_field_name';
9497
}
98+
9599
if (! isset(static::$fields[$field]))
96100
{
97101
throw new \PHPFUI\ConstantContact\Exception\InvalidField(static::class . "::{$actualField} is not a valid field");
@@ -108,7 +112,8 @@ public function __get(string $field) : mixed
108112
public function __set(string $field, $value)
109113
{
110114
$actualField = $field;
111-
if (str_starts_with($field, 'cf_'))
115+
116+
if (\str_starts_with($field, 'cf_'))
112117
{
113118
$field = 'cf:custom_field_name';
114119
}
@@ -267,7 +272,7 @@ public function getData() : array
267272
}
268273
else
269274
{
270-
$result[str_replace('cf_', 'cf:', $field)] = \is_object($value) ? (string)$value : $value;
275+
$result[\str_replace('cf_', 'cf:', $field)] = \is_object($value) ? (string)$value : $value;
271276
}
272277
}
273278
}

0 commit comments

Comments
 (0)