Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
csfixes and resolver issue fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorkmaz committed May 10, 2021
1 parent 090f0ad commit 51b32e7
Show file tree
Hide file tree
Showing 25 changed files with 352 additions and 207 deletions.
13 changes: 11 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
],
"minimum-stability": "stable",
"require": {
"php": "^7.3 | ~8.0.0"
"php": "^7.4 | ~8.0.0",
"psr/container": "^1.0"
},
"require-dev": {
"codeception/codeception": "^4.1",
"php-coveralls/php-coveralls": "^v2.2.0",
"codeception/module-asserts": "^1.2"
"codeception/module-asserts": "^1.2",
"squizlabs/php_codesniffer": "^3.6",
"doctrine/coding-standard": "^9.0"
},
"autoload": {
"psr-4": {
Expand All @@ -27,6 +30,12 @@
"psr-4": {
"Selami\\Resources\\" : "tests/resources/src/"
}
},
"scripts": {

"cs-check": "vendor/bin/phpcs --standard=Doctrine",
"cs-fix": "vendor/bin/phpcbf --standard=Doctrine"

}

}
36 changes: 21 additions & 15 deletions src/BaseUrlExtractor.php
Original file line number Diff line number Diff line change
@@ -1,49 +1,55 @@
<?php

declare(strict_types=1);

namespace Selami\Stdlib;

use function basename;
use function strpos;
use function substr;
use function trim;

class BaseUrlExtractor
{
public static function getBaseUrl(array $httpServerData) : string
public static function getBaseUrl(array $httpServerData): string
{
$protocol = self::getProtocol($httpServerData);
$host = self::getHost($httpServerData);
$uriPath = $httpServerData['REQUEST_URI'] ?? '';
$filename = $httpServerData['SCRIPT_FILENAME'] ?? '';
$protocol = self::getProtocol($httpServerData);
$host = self::getHost($httpServerData);
$uriPath = $httpServerData['REQUEST_URI'] ?? '';
$filename = $httpServerData['SCRIPT_FILENAME'] ?? '';
$scriptName = $httpServerData['SCRIPT_NAME'];
$phpSelf = $httpServerData['PHP_SELF'];
$baseUrl = self::getRelativeBaseUrl($scriptName, $phpSelf, $filename);
$phpSelf = $httpServerData['PHP_SELF'];
$baseUrl = self::getRelativeBaseUrl($scriptName, $phpSelf, $filename);

return trim($protocol . '://' . $host . $baseUrl, '/');
}



public static function getProtocol(array $httpServerData) : string
public static function getProtocol(array $httpServerData): string
{
if (isset($httpServerData['HTTP_X_FORWARDED_PROTO'])) {
return $httpServerData['HTTP_X_FORWARDED_PROTO'];
}
return isset($httpServerData['HTTPS']) && $httpServerData['HTTPS'] !== 'Off' ? 'https': 'http';

return isset($httpServerData['HTTPS']) && $httpServerData['HTTPS'] !== 'Off' ? 'https' : 'http';
}

public static function getHost($httpServerData) : string
public static function getHost($httpServerData): string
{
return $httpServerData['HTTP_HOST'];
}

public static function getRelativeBaseUrl($scriptName, $phpSelf, $filename) : string
public static function getRelativeBaseUrl($scriptName, $phpSelf, $filename): string
{

// Backtrack up the SCRIPT_FILENAME to find the portion
// matching PHP_SELF.
$baseUrl = '/';
$basename = basename($filename);
if ($basename) {
$path = ($phpSelf ? trim($phpSelf, '/') : '');
$basePos = strpos($path, $basename) ?: 0;
$baseUrl .= substr($path, 0, $basePos) ;
$baseUrl .= substr($path, 0, $basePos);
}

return $baseUrl;
}
}
39 changes: 18 additions & 21 deletions src/CaseConverter.php
Original file line number Diff line number Diff line change
@@ -1,53 +1,50 @@
<?php

declare(strict_types=1);

namespace Selami\Stdlib;

use function lcfirst;
use function mb_convert_case;
use function mb_strtolower;
use function preg_replace;
use function str_replace;
use function trim;

use const MB_CASE_TITLE;

class CaseConverter
{
/**
* Returns PascalCase string
*
* @param string $source
* @param string $separator
* @return string
*
*/
public static function toPascalCase(string $source, string $separator = '_') : string
public static function toPascalCase(string $source, string $separator = '_'): string
{
// If the string is snake case
$modified = str_replace($separator, ' ', $source);
$lowercase = mb_strtolower($modified);
$modified = str_replace($separator, ' ', $source);
$lowercase = mb_strtolower($modified);
$uppercaseFirstLetters = mb_convert_case($lowercase, MB_CASE_TITLE);

return str_replace(' ', '', $uppercaseFirstLetters);
}

/**
* Returns camelCase string
*
* @param string $source
* @param string $separator
* @return string
*
*/
public static function toCamelCase(string $source, string $separator = '_') : string
public static function toCamelCase(string $source, string $separator = '_'): string
{
return lcfirst(self::toPascalCase($source, $separator));
}

/**
* Returns snake_case string
*
* @param string $source
* @param string $separator
* @return string
*
*/
public static function toSnakeCase(string $source, string $separator = '_') : string
public static function toSnakeCase(string $source, string $separator = '_'): string
{
// If the string is pascal/camel case
$modified = str_replace(' ', ' ', preg_replace('/[A-Z]+/', ' $0', $source));
$modified = str_replace(' ', ' ', preg_replace('/[A-Z]+/', ' $0', $source));
$lowercase = mb_strtolower(trim($modified));

return str_replace(' ', $separator, $lowercase);
}
}
47 changes: 31 additions & 16 deletions src/EqualsBuilder.php
Original file line number Diff line number Diff line change
@@ -1,108 +1,123 @@
<?php

declare(strict_types=1);

namespace Selami\Stdlib;

use ReflectionClass;

use function is_object;

/**
* Class EqualsBuilder
*
* This class provides methods to build a equals method for any class. Intended to be use to compare Value Objects.
* @package Selami\Stdlib
*
*/

final class EqualsBuilder
{
private $isEquals = true;

public static function create() : EqualsBuilder
public static function create(): EqualsBuilder
{
return new static();
}

public function append($leftHandedValue, $rightHandedValue)
{
if ($this->isEquals === false) {
return $this;
}

if ($this->checkIfValuesAreAnObjectAndEqual($leftHandedValue, $rightHandedValue)) {
return $this;
}

if ($this->checkForSameType($leftHandedValue, $rightHandedValue)) {
return $this;
}

return $this;
}

private function checkForSameType($leftHandedValue, $rightHandedValue) :bool
private function checkForSameType($leftHandedValue, $rightHandedValue): bool
{
if ($leftHandedValue !== $rightHandedValue) {
$this->isEquals = false;

return false;
}

return true;
}

private function checkIfValuesAreAnObjectAndEqual($leftHandedValue, $rightHandedValue) : bool
private function checkIfValuesAreAnObjectAndEqual($leftHandedValue, $rightHandedValue): bool
{
if (! $this->checkIfValuesAreAnObject($leftHandedValue, $rightHandedValue)) {
return false;
}
if (get_class($leftHandedValue) !== get_class($rightHandedValue)) {

if ($leftHandedValue::class !== $rightHandedValue::class) {
$this->isEquals = false;

return false;
}

if (! $this->compareObjectProperties($leftHandedValue, $rightHandedValue)) {
$this->isEquals = false;

return false;
}

return true;
}
private function checkIfValuesAreAnObject($leftHandedValue, $rightHandedValue) : bool

private function checkIfValuesAreAnObject($leftHandedValue, $rightHandedValue): bool
{
return (is_object($leftHandedValue) && is_object($rightHandedValue));
return is_object($leftHandedValue) && is_object($rightHandedValue);
}

private function compareObjectProperties($leftHandedObject, $rightHandedObject) : bool
private function compareObjectProperties($leftHandedObject, $rightHandedObject): bool
{
$reflectionOfLeftHandedObject = new ReflectionClass($leftHandedObject);
$propertiesOfLeftHandedObject = $this->getPropertiesAsAnArray($leftHandedObject, $reflectionOfLeftHandedObject);
$reflectionOfLeftHandedObject = new ReflectionClass($leftHandedObject);
$propertiesOfLeftHandedObject = $this->getPropertiesAsAnArray($leftHandedObject, $reflectionOfLeftHandedObject);
$reflectionOfRightHandedObject = new ReflectionClass($rightHandedObject);
$propertiesOfRightHandedObject = $this->getPropertiesAsAnArray(
$rightHandedObject,
$reflectionOfRightHandedObject
);

return $this->checkValuesRecursively($propertiesOfRightHandedObject, $propertiesOfLeftHandedObject);
}

private function checkValuesRecursively(
array $propertiesOfLeftHandedObject,
array $propertiesOfRightHandedObject
) : bool {
): bool {
$innerEqualsBuilder = self::create();
foreach ($propertiesOfLeftHandedObject as $propertyName => $propertyValue) {
$innerEqualsBuilder = $innerEqualsBuilder->append(
$propertyValue,
$propertiesOfRightHandedObject[$propertyName]
);
}

return $innerEqualsBuilder->isEquals();
}

private function getPropertiesAsAnArray($sourceObject, $object) :array
private function getPropertiesAsAnArray($sourceObject, $object): array
{
$propertyList = [];
foreach ($object->getProperties() as $property) {
if ($property->isProtected() || $property->isPrivate()) {
$property->setAccessible(true);
}

$propertyList[$property->name] = $property->getValue($sourceObject);
}

return $propertyList;
}

public function isEquals() : bool
public function isEquals(): bool
{
return $this->isEquals;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Exception/ClassOrMethodCouldNotBeFound.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

declare(strict_types=1);

namespace Selami\Stdlib\Exception;

class ClassOrMethodCouldNotBeFound extends \InvalidArgumentException
{
use InvalidArgumentException;

class ClassOrMethodCouldNotBeFound extends InvalidArgumentException
{
}
2 changes: 1 addition & 1 deletion src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

declare(strict_types=1);

namespace Selami\Stdlib\Exception;

class InvalidArgumentException extends \InvalidArgumentException
{

}
6 changes: 4 additions & 2 deletions src/Exception/InvalidSemverPatternException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

declare(strict_types=1);

namespace Selami\Stdlib\Exception;

class InvalidSemverPatternException extends \InvalidArgumentException
{
use InvalidArgumentException;

class InvalidSemverPatternException extends InvalidArgumentException
{
}
4 changes: 4 additions & 0 deletions src/Git/Version.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<?php

declare(strict_types=1);

namespace Selami\Stdlib\Git;

use function exec;

final class Version
{
public static function short()
{
exec('git describe --always', $versionMiniHash);

return $versionMiniHash[0];
}
}
11 changes: 11 additions & 0 deletions src/Pipeline/InvalidStageException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Selami\Stdlib\Pipeline;

use Exception;

class InvalidStageException extends Exception
{
}
Loading

0 comments on commit 51b32e7

Please sign in to comment.