Skip to content

Commit 7907540

Browse files
committed
Add initial set of files
0 parents  commit 7907540

59 files changed

Lines changed: 2219 additions & 0 deletions

Some content is hidden

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

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# dependencies
2+
vendor/
3+
4+
# caches, logs etc.
5+
composer.lock
6+
.phpunit.cache
7+
.php-cs-fixer.cache
8+
.phpbench/
9+
10+
# script-templates
11+
## Ignore all subdirectories under scripts (script-template folders)
12+
scripts/*/
13+
## Except for the hooks folder (allows to hook into several script-template scripts)
14+
!scripts/hooks/
15+
## Recursively ignore any file ending with .local.sh (local files which you wont want to commit)
16+
scripts/*.local.sh
17+
scripts/**/*.local.sh

.php-cs-fixer.dist.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
if (!file_exists(__DIR__.'/src')) {
4+
exit(0);
5+
}
6+
7+
return (new PhpCsFixer\Config())
8+
// @see https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/pull/7777
9+
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
10+
->setRules([
11+
'@PHP71Migration' => true,
12+
'@PHPUnit75Migration:risky' => true,
13+
'@Symfony' => true,
14+
'@Symfony:risky' => true,
15+
'protected_to_private' => false,
16+
])
17+
->setRiskyAllowed(true)
18+
->setFinder(
19+
(new PhpCsFixer\Finder())
20+
->in([__DIR__.'/src', __DIR__.'/config'])
21+
->append([__FILE__])
22+
)
23+
->setCacheFile('.php-cs-fixer.cache');

.phpunit.result.cache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":1,"defects":{"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testCrossConvert":8,"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testCrossConvert#0":7,"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testCrossConvert#1":7,"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testCrossConvert#2":7,"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testCrossConvert#3":7,"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testCrossConvert#4":7,"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testCrossConvert#5":7,"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testCrossConvert#6":7,"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testCrossConvert#7":7,"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testCrossConvert#8":7,"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testCrossConvert#9":7},"times":{"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testCrossConvert":0.005,"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testConvertSamePrefix":0.001,"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testConversionIntoInvalidPrefix":0.001,"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testSetDecimalSeparator":0,"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testCrossConvert#0":0.01,"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testCrossConvert#1":0.002,"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testCrossConvert#2":0.002,"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testCrossConvert#3":0.001,"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testCrossConvert#4":0.001,"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testCrossConvert#5":0.001,"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testCrossConvert#6":0.001,"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testCrossConvert#7":0.001,"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testCrossConvert#8":0.001,"SoureCode\\Bundle\\Unit\\Tests\\Conversion\\LengthConverterTest::testCrossConvert#9":0.001}}

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
# sourecode/unit-bundle
3+
4+
This bundle provides a simple way to handle unit of measurements in Symfony applications.
5+
6+
## Installation
7+
8+
Make sure Composer is installed globally, as explained in the
9+
[installation chapter](https://getcomposer.org/doc/00-intro.md)
10+
of the Composer documentation.
11+
12+
### Applications that use Symfony Flex
13+
14+
Open a command console, enter your project directory and execute:
15+
16+
```console
17+
composer require sourecode/unit-bundle
18+
```
19+
20+
### Applications that don't use Symfony Flex
21+
22+
#### Step 1: Download the Bundle
23+
24+
Open a command console, enter your project directory and execute the
25+
following command to download the latest stable version of this bundle:
26+
27+
```console
28+
composer require sourecode/unit-bundle
29+
```
30+
31+
#### Step 2: Enable the Bundle
32+
33+
Then, enable the bundle by adding it to the list of registered bundles
34+
in the `config/bundles.php` file of your project:
35+
36+
```php
37+
// config/bundles.php
38+
39+
return [
40+
// ...
41+
\SoureCode\Bundle\Unit\SoureCodeUnitBundle::class => ['all' => true],
42+
];
43+
```
44+
45+
## Config
46+
47+
```yaml
48+
# config/packages/soure_code_unit.yaml
49+
# @todo
50+
```

composer.json

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"name": "sourecode/unit-bundle",
3+
"license": "MIT",
4+
"type": "symfony-bundle",
5+
"authors": [
6+
{
7+
"name": "chapterjason",
8+
"email": "jason@sourecode.dev"
9+
}
10+
],
11+
"require": {
12+
"php": ">=8.4",
13+
"ext-bcmath": "*",
14+
"ext-intl": "*",
15+
"symfony/config": "^7.1",
16+
"symfony/dependency-injection": "^7.1",
17+
"symfony/http-kernel": "^7.1",
18+
"symfony/intl": "^7.1"
19+
},
20+
"require-dev": {
21+
"brainmaestro/composer-git-hooks": "^3.0",
22+
"doctrine/dbal": "^3.9.4",
23+
"doctrine/doctrine-bundle": "^2.13.2",
24+
"doctrine/orm": "^3.3.2",
25+
"ergebnis/composer-normalize": "^2.45",
26+
"nyholm/symfony-bundle-test": "^3.0",
27+
"php-cs-fixer/shim": "^3.75",
28+
"phpunit/phpunit": "^12.1",
29+
"psalm/plugin-symfony": "^5.2",
30+
"symfony/browser-kit": "^7.1",
31+
"symfony/clock": "^7.1",
32+
"symfony/form": "^7.1",
33+
"symfony/runtime": "^7.1",
34+
"twig/twig": "^3.2",
35+
"vimeo/psalm": "^6.10"
36+
},
37+
"autoload": {
38+
"psr-4": {
39+
"SoureCode\\Bundle\\Unit\\": "src/"
40+
}
41+
},
42+
"autoload-dev": {
43+
"psr-4": {
44+
"App\\": "tests/app/src/",
45+
"SoureCode\\Bundle\\Unit\\Tests\\": "tests/"
46+
}
47+
},
48+
"config": {
49+
"allow-plugins": {
50+
"ergebnis/composer-normalize": true,
51+
"symfony/runtime": true
52+
}
53+
},
54+
"extra": {
55+
"hooks": {
56+
"config": {
57+
"stop-on-failure": [
58+
"pre-commit",
59+
"pre-push"
60+
]
61+
},
62+
"pre-commit": [
63+
"composer normalize",
64+
"PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix"
65+
],
66+
"pre-push": [
67+
"composer normalize --dry-run",
68+
"PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --dry-run",
69+
"vendor/bin/phpunit",
70+
"vendor/bin/psalm --no-cache"
71+
]
72+
}
73+
},
74+
"scripts": {
75+
"post-install-cmd": "vendor/bin/cghooks add",
76+
"post-update-cmd": "vendor/bin/cghooks update"
77+
}
78+
}

config/packages/doctrine.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
use SoureCode\Bundle\Unit\Doctrine\DBAL\Types\LengthType;
4+
use Symfony\Component\DependencyInjection\ContainerBuilder;
5+
6+
return static function (ContainerBuilder $containerBuilder) {
7+
$containerBuilder->prependExtensionConfig('doctrine', [
8+
'dbal' => [
9+
'types' => [
10+
LengthType::NAME => LengthType::class,
11+
],
12+
],
13+
]);
14+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use SoureCode\Bundle\Unit\Model\Metric\Length\Centimeter;
4+
use SoureCode\Bundle\Unit\Model\Metric\Length\Decameter;
5+
use SoureCode\Bundle\Unit\Model\Metric\Length\Decimeter;
6+
use SoureCode\Bundle\Unit\Model\Metric\Length\Hectometer;
7+
use SoureCode\Bundle\Unit\Model\Metric\Length\Kilometer;
8+
use SoureCode\Bundle\Unit\Model\Metric\Length\Meter;
9+
use SoureCode\Bundle\Unit\Model\Metric\Length\Micrometer;
10+
use SoureCode\Bundle\Unit\Model\Metric\Length\Millimeter;
11+
use SoureCode\Bundle\Unit\Model\Metric\Length\Nanometer;
12+
use SoureCode\Bundle\Unit\Model\Metric\Length\Picometer;
13+
use SoureCode\Bundle\Unit\Model\Metric\Prefix;
14+
use Symfony\Component\DependencyInjection\ContainerBuilder;
15+
16+
return static function (ContainerBuilder $containerBuilder) {
17+
$containerBuilder->prependExtensionConfig('soure_code_unit', [
18+
'units' => [
19+
'length' => [
20+
'mapping' => [
21+
Prefix::KILO->value => Kilometer::class,
22+
Prefix::HECTO->value => Hectometer::class,
23+
Prefix::DECA->value => Decameter::class,
24+
Prefix::BASE->value => Meter::class,
25+
Prefix::DECI->value => Decimeter::class,
26+
Prefix::CENTI->value => Centimeter::class,
27+
Prefix::MILLI->value => Millimeter::class,
28+
Prefix::MICRO->value => Micrometer::class,
29+
Prefix::NANO->value => Nanometer::class,
30+
Prefix::PICO->value => Picometer::class,
31+
],
32+
],
33+
],
34+
]);
35+
};

phpunit.xml.dist

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.1/phpunit.xsd"
4+
backupGlobals="false"
5+
colors="false"
6+
processIsolation="false"
7+
stopOnFailure="false"
8+
bootstrap="./vendor/autoload.php"
9+
cacheDirectory=".phpunit.cache"
10+
backupStaticProperties="false"
11+
>
12+
<testsuites>
13+
<testsuite name="Test Suite">
14+
<directory>./tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
<php>
18+
<ini name="intl.default_locale" value="de-DE"/>
19+
<env name="DATABASE_URL" value="sqlite:///:memory:"/>
20+
</php>
21+
<source>
22+
<include>
23+
<directory suffix=".php">./</directory>
24+
</include>
25+
<exclude>
26+
<directory>vendor</directory>
27+
<directory>tests</directory>
28+
</exclude>
29+
</source>
30+
</phpunit>

psalm.xml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="4"
4+
resolveFromConfigFile="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xmlns="https://getpsalm.org/schema/config"
7+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
findUnusedBaselineEntry="false"
9+
findUnusedCode="false"
10+
findUnusedIssueHandlerSuppression="false"
11+
ensureOverrideAttribute="false"
12+
>
13+
<projectFiles>
14+
<directory name="src"/>
15+
<ignoreFiles>
16+
<directory name="vendor"/>
17+
</ignoreFiles>
18+
</projectFiles>
19+
20+
<issueHandlers>
21+
<UnusedClass>
22+
<errorLevel type="suppress">
23+
<directory name="src"/>
24+
</errorLevel>
25+
</UnusedClass>
26+
<UndefinedInterfaceMethod>
27+
<errorLevel type="suppress">
28+
<referencedMethod name="Symfony\Component\Config\Definition\Builder\NodeParentInterface::validate"/>
29+
</errorLevel>
30+
</UndefinedInterfaceMethod>
31+
</issueHandlers>
32+
33+
<forbiddenFunctions>
34+
<function name="empty"/>
35+
</forbiddenFunctions>
36+
<plugins>
37+
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
38+
</plugins>
39+
</psalm>

scripts/__dev.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
CURRENT_DIRECTORY="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
PROJECT_DIRECTORY="$(dirname "${CURRENT_DIRECTORY}")"
7+
8+
function _main() {
9+
pushd "${PROJECT_DIRECTORY}" >/dev/null 2>&1
10+
11+
if [ -d "${PROJECT_DIRECTORY:?}/scripts/public-common" ]; then
12+
bash "${PROJECT_DIRECTORY:?}/scripts/public-common/update-template.sh"
13+
else
14+
git clone --depth 1 -b "master" "git@github.com:SoureCode/public-common-script-template.git" "scripts/public-common"
15+
bash "${PROJECT_DIRECTORY:?}/scripts/public-common/___cleanup.sh"
16+
fi
17+
18+
popd >/dev/null 2>&1
19+
}
20+
21+
_main

0 commit comments

Comments
 (0)