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

Commit 51ced5d

Browse files
committed
first commit
0 parents  commit 51ced5d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3535
-0
lines changed

Diff for: .coveralls.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# .coveralls.yml configuration
2+
service_name: travis-ci
3+
coverage_clover: tests/_output/coverage.xml

Diff for: .scrutinizer.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# .scrutinizer.yml
2+
3+
checks:
4+
php:
5+
code_rating: true
6+
duplication: true
7+
build:
8+
environment:
9+
php: '7.1'
10+
filter:
11+
excluded_paths:
12+
- "tests/"

Diff for: .travis.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
language: php
2+
sudo: false
3+
cache:
4+
apt: true
5+
6+
php:
7+
- 7.1
8+
9+
before_script:
10+
- composer install --prefer-source
11+
script:
12+
- vendor/bin/codecept run --coverage --coverage-xml --coverage-html
13+
after_script:
14+
- if [ $TRAVIS_PHP_VERSION >= '7.0' ]; then php vendor/bin/coveralls; fi
15+
after_success:
16+
- travis_retry php vendor/bin/coveralls -v
17+
18+

Diff for: codeception.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
paths:
2+
tests: tests
3+
output: tests/_output
4+
data: tests/_data
5+
support: tests/_support
6+
envs: tests/_envs
7+
actor_suffix: Tester
8+
extensions:
9+
enabled:
10+
- Codeception\Extension\RunFailed
11+
coverage:
12+
enabled: true
13+
include:
14+
- src/*

Diff for: composer.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "selami/stdlib",
3+
"description": "Standart Library for Selami libraries.",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Mehmet Korkmaz",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"minimum-stability": "stable",
13+
"require": {},
14+
"require-dev": {
15+
"codeception/codeception": "^2.3",
16+
"satooshi/php-coveralls": "~1.0"
17+
18+
},
19+
"autoload": {
20+
"psr-4": {
21+
"Selami\\Stdlib\\": "src/"
22+
}
23+
},
24+
"autoload-dev": {
25+
"psr-4": {
26+
"Selami\\Resources\\" : "tests/resources/src/"
27+
}
28+
}
29+
30+
}

Diff for: src/CaseConverter.php

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Selami\Stdlib;
5+
6+
7+
class CaseConverter
8+
{
9+
/**
10+
* Returns PascalCase string
11+
*
12+
* @param string $source
13+
* @return string
14+
*
15+
*/
16+
public static function toPascalCase(string $source) : string
17+
{
18+
// If the string is snake case
19+
$modified = str_replace('_', ' ', $source);
20+
$lowercase = mb_strtolower($modified);
21+
$uppercaseFirstLetters = mb_convert_case($lowercase, MB_CASE_TITLE);
22+
return str_replace(' ', '', $uppercaseFirstLetters);
23+
}
24+
25+
/**
26+
* Returns camelCase string
27+
*
28+
* @param string $source
29+
* @return string
30+
*
31+
*/
32+
public static function toCamelCase(string $source) : string
33+
{
34+
return lcfirst(self::toPascalCase($source));
35+
}
36+
37+
/**
38+
* Returns snake_case string
39+
*
40+
* @param string $source
41+
* @return string
42+
*
43+
*/
44+
public static function toSnakeCase(string $source) : string
45+
{
46+
// If the string is pascal/camel case
47+
$modified = preg_replace('/(\w)([A-Z]+)/', ' $1', $source);
48+
$lowercase = mb_strtolower($modified);
49+
return str_replace(' ', '_', $lowercase);
50+
}
51+
52+
}

Diff for: src/Exception/InvalidArgumentException.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Selami\Stdlib\Exception;
5+
6+
7+
class InvalidArgumentException extends \InvalidArgumentException
8+
{
9+
10+
}

Diff for: src/Resolver.php

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Selami\Stdlib;
5+
6+
use ReflectionMethod;
7+
use ReflectionParameter;
8+
use Selami\Stdlib\Exception\InvalidArgumentException;
9+
use ReflectionException;
10+
11+
class Resolver
12+
{
13+
/**
14+
* @param string $className
15+
* @param string $methodName
16+
* @return array
17+
* @throws InvalidArgumentException
18+
*/
19+
20+
public static function getParameterHints(string $className, string $methodName) : array
21+
{
22+
if (! class_exists($className)) {
23+
throw new InvalidArgumentException(
24+
sprintf('%s class does not exist!', $className)
25+
);
26+
}
27+
if (! method_exists($className, $methodName)) {
28+
throw new InvalidArgumentException(
29+
sprintf('%s does not have method named %s!', $className, $methodName)
30+
);
31+
}
32+
$method = new ReflectionMethod($className, $methodName);
33+
/**
34+
* @var array $parameters
35+
*/
36+
$parameters = $method->getParameters();
37+
$parameterHints = [];
38+
foreach ($parameters as $param) {
39+
$parameter = self::getParamType($param);
40+
$parameterHints[$parameter['name']] = $parameter['type'];
41+
}
42+
return $parameterHints;
43+
}
44+
45+
46+
/**
47+
* @param ReflectionParameter $parameter
48+
* @return array
49+
* @throws InvalidArgumentException
50+
*/
51+
private static function getParamType(ReflectionParameter $parameter) :array
52+
{
53+
$type = $parameter->getType();
54+
if ($type->isBuiltin()) {
55+
return ['name' => $parameter->getName(), 'type' => (string) $type];
56+
}
57+
try {
58+
return ['name' => $parameter->getName(), 'type' =>$parameter->getClass()->name];
59+
} catch (ReflectionException $e) {
60+
throw new InvalidArgumentException($e->getMessage());
61+
}
62+
}
63+
64+
}

Diff for: tests/_data/.gitkeep

Whitespace-only changes.

Diff for: tests/_output/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)