Skip to content

Commit

Permalink
Update repository. (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw authored Jan 23, 2024
1 parent 04a6e5a commit 838268d
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 88 deletions.
6 changes: 3 additions & 3 deletions .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ enabled:
- combine_nested_dirname
- declare_strict_types
- dir_constant
- empty_loop_body_braces
- fully_qualified_strict_types
- function_to_constant
- hash_to_slash_comment
- integer_literal_case
- is_null
- logical_operators
- magic_constant_casing
Expand Down Expand Up @@ -56,7 +58,6 @@ enabled:
- phpdoc_order
- phpdoc_property
- phpdoc_scalar
- phpdoc_separation
- phpdoc_singular_inheritdoc
- phpdoc_trim
- phpdoc_trim_consecutive_blank_line_separation
Expand All @@ -78,9 +79,8 @@ enabled:
- trailing_comma_in_multiline_array
- unalign_double_arrow
- unalign_equals
- empty_loop_body_braces
- integer_literal_case
- union_type_without_spaces

disabled:
- function_declaration
- psr12_braces
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Change Log
==========

## 0.1.0 January 23, 2024

- Initial release.
49 changes: 35 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,47 @@
<img src="https://avatars.githubusercontent.com/u/103309199?s%253D400%2526u%253Dca3561c692f53ed7eb290d3bb226a2828741606f%2526v%253D4" height="100px">
</a>
<a href="https://github.com/php-forge/awesome-widget" target="_blank">
<img src="https://cdn-icons-png.flaticon.com/512/5762/5762492.png" height="100px">
<img src="https://raw.githubusercontent.com/php-forge/awesome-widget/update-repository/docs/image/logo.png" height="100px">
</a>
<h1 align="center">Foundation Classes and Components for Awesome Widget</h1>
<h1 align="center">Foundation Classes and Components for Awesome Widget.</h1>
<br>
</p>

## Requirements
<p align="center">
<a href="https://github.com/php-forge/awesome-widget/actions/workflows/build.yml" target="_blank">
<img src="https://github.com/php-forge/awesome-widget/actions/workflows/build.yml/badge.svg" alt="PHPUnit">
</a>
<a href="https://codecov.io/gh/php-forge/awesome-widget" target="_blank">
<img src="https://codecov.io/gh/php-forge/awesome-widget/branch/main/graph/badge.svg?token=MF0XUGVLYC" alt="Codecov">
</a>
<a href="https://dashboard.stryker-mutator.io/reports/github.com/php-forge/awesome-widget/main" target="_blank">
<img src="https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fphp-forge%2Fawesome-widget%2Fmain" alt="Infection">
</a>
<a href="https://github.com/php-forge/awesome-widget/actions/workflows/static.yml" target="_blank">
<img src="https://github.com/php-forge/awesome-widget/actions/workflows/static.yml/badge.svg" alt="Psalm">
</a>
<a href="https://shepherd.dev/github/php-forge/awesome-widget" target="_blank">
<img src="https://shepherd.dev/github/php-forge/awesome-widget/coverage.svg" alt="Psalm Coverage">
</a>
<a href="https://github.styleci.io/repos/494784194?branch=main" target="_blank">
<img src="https://github.styleci.io/repos/494784194/shield?branch=main" alt="Style ci">
</a>
</p>

The minimun version of `PHP` required by this package is `PHP 8.1`.
## Installation

For install this package, you need [composer](https://getcomposer.org/).
The preferred way to install this extension is through [composer](https://getcomposer.org/download/).

## Install
Either run

```shell
composer require php-forge/awesome-widget
composer require --prefer-dist php-forge/awesome-widget:"^0.1"
```

or add

```json
"php-forge/awesome-widget": "^0.1"
```

## Usage
Expand All @@ -29,14 +54,10 @@ composer require php-forge/awesome-widget

[Check the documentation testing](/docs/testing.md) to learn about testing.

## CI status
## Support versions

[![build](https://github.com/php-forge/awesome-widget/actions/workflows/build.yml/badge.svg)](https://github.com/php-forge/awesome-widget/actions/workflows/build.yml)
[![codecov](https://codecov.io/gh/php-forge/awesome-widget/branch/main/graph/badge.svg?token=Hpxye21BHA)](https://codecov.io/gh/php-forge/awesome-widget)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fphp-forge%2Fawesome-widget%2Fmain)](https://dashboard.stryker-mutator.io/reports/github.com/php-forge/awesome-widget/main)
[![static analysis](https://github.com/php-forge/awesome-widget/actions/workflows/static.yml/badge.svg)](https://github.com/php-forge/awesome-widget/actions/workflows/static.yml)
[![type-coverage](https://shepherd.dev/github/php-forge/awesome-widget/coverage.svg)](https://shepherd.dev/github/php-forge/awesome-widget)
[![ecs](https://github.com/php-forge/awesome-widget/actions/workflows/ecs.yml/badge.svg)](https://github.com/php-forge/awesome-widget/actions/workflows/ecs.yml)
[![PHP81](https://img.shields.io/badge/PHP-%3E%3D8.1-787CB5)](https://www.php.net/releases/8.1/en.php)
[![Yii30](https://img.shields.io/badge/Yii%20version-3.0-blue)](https://yiiframework.com)

## Our social networks

Expand Down
2 changes: 0 additions & 2 deletions changelog.md

This file was deleted.

28 changes: 15 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@
"awesome-widget"
],
"license": "mit",
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^8.1"
},
"require-dev": {
"maglnet/composer-require-checker": "^4.3",
"php-forge/support": "^1.0@dev",
"phpunit/phpunit": "^10.0",
"roave/infection-static-analysis-plugin": "^1.30",
"symplify/easy-coding-standard": "^12.0",
"vimeo/psalm": "^5.6"
"maglnet/composer-require-checker": "^4.7",
"php-forge/support": "^0.1",
"phpunit/phpunit": "^10.5",
"roave/infection-static-analysis-plugin": "^1.34",
"symplify/easy-coding-standard": "^12.1",
"vimeo/psalm": "^5.20"
},
"autoload": {
"psr-4": {
Expand All @@ -32,19 +30,23 @@
},
"extra": {
"branch-alias": {
"dev-main": "1.0.x-dev"
"dev-main": "0.1-dev"
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"infection/extension-installer": true
}
},
"sort-packages": true
},
"scripts": {

"check-dependencies": "composer-require-checker",
"easy-coding-standard": "ecs check",
"mutation": "roave-infection-static-analysis-plugin",
"ecs": "ecs check",
"mutation": [
"Composer\\Config::disableProcessTimeout",
"roave-infection-static-analysis-plugin"
],
"psalm": "psalm",
"test": "phpunit"
}
Expand Down
46 changes: 41 additions & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ element.

They may also be used in `forms` to generate the needed `HTML` code for displaying the corresponding form field.

## Usage
# Usage

Widgets are primarily used in view.

Expand Down Expand Up @@ -38,7 +38,7 @@ That would generate the following code:
<id="id-test" class="text-danger">
```

### Definition array
## Definition array

The `definitions` array is used to define the widget's properties and methods.

Expand All @@ -63,6 +63,39 @@ That would generate the following code:
<class="test-class">
```

## Load default definitions

You can load the default definitions by calling the `PHPForge\Widget\Widget::loadDefaultDefinitions()` method.

```php
<?php

declare(strict_types=1);

final class DefaultDefinition extends Element
{
private string $id = '';

public function id(string $value): self
{
$new = clone $this;
$new->id = $value;

return $new;
}

/**
* This method is used to configure the widget with the provided default definitions.
*/
protected function loadDefaultDefinitions(): array
{
return [
'id()' => ['id-default-definitions'],
];
}
}
```

## Creating

To create a widget, you need to extend the `PHPForge\Widget\AbstractWidget::class` and implement the `PHPForge\Widget\Widget::run()` protected method.
Expand Down Expand Up @@ -92,7 +125,8 @@ final class Widget extends AbstractWidget

Widgets may capture the content inside between the `begin()` and `end()` calls.

This is useful when you want to generate a widget that has some content. For example, you may want to generate a widget that mimics opening and closing HTML tags.
This is useful when you want to generate a widget that has some content. For example, you may want to generate a widget
that mimics opening and closing HTML tags.

For your widget to do this, you need to override the `parent begin()` method and don't forget to call `parent::begin()`:

Expand Down Expand Up @@ -136,7 +170,8 @@ Then you can use the widget like the following:

The `beforeRun()` method is called right before running the widget.

The return value of the method will decide whether the widget should continue to run. When overriding this method, make sure you call the `parent` implementation like the following:
The return value of the method will decide whether the widget should continue to run. When overriding this method, make
sure you call the `parent` implementation like the following:

```php
protected function beforeRun(): bool
Expand All @@ -151,7 +186,8 @@ protected function beforeRun(): bool

## After run

The `afterRun()` method is called right after running the widget. The return value of the method will be used as the widget's return value. When overriding this method, make sure you call the `parent` implementation like the following:
The `afterRun()` method is called right after running the widget. The return value of the method will be used as the
widget's return value. When overriding this method, make sure you call the `parent` implementation like the following:

```php
protected function afterRun(string $result): string
Expand Down
Binary file added docs/image/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 26 additions & 23 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,40 @@

declare(strict_types=1);

use PhpCsFixer\Fixer\ClassNotation\ClassDefinitionFixer;
use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer;
use PhpCsFixer\Fixer\ClassNotation\OrderedTraitsFixer;
use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
use PhpCsFixer\Fixer\ClassNotation\OrderedTraitsFixer;
use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer;

return function (ECSConfig $ecsConfig): void {
$ecsConfig->paths(
return ECSConfig::configure()
->withConfiguredRule(
ClassDefinitionFixer::class,
[
'space_before_parenthesis' => true,
],
)
->withFileExtensions(['php'])
->withPaths(
[
__DIR__ . '/src',
__DIR__ . '/tests',
]
);

// this way you add a single rule
$ecsConfig->rules(
],
)
->withPhpCsFixerSets(perCS20: true)
->withPreparedSets(
arrays: true,
cleanCode: true,
comments:true,
docblocks: true,
namespaces: true,
psr12: true,
strict: true
)
->withRules(
[
NoUnusedImportsFixer::class,
OrderedClassElementsFixer::class,
OrderedTraitsFixer::class,
NoUnusedImportsFixer::class,
]
);

// this way you can add sets - group of rules
$ecsConfig->sets(
[
// run and fix, one by one
SetList::DOCBLOCK,
SetList::NAMESPACES,
SetList::COMMENTS,
SetList::PSR_12,
]
);
};
38 changes: 19 additions & 19 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
colors="true"
executionOrder="depends,defects"
failOnRisky="true"
failOnWarning="true"
stopOnFailure="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
colors="true"
executionOrder="depends,defects"
failOnRisky="true"
failOnWarning="true"
stopOnFailure="false"
>
<testsuites>
<testsuite name="AwesomeWidget">
<directory>tests</directory>
</testsuite>
</testsuites>
<testsuites>
<testsuite name="Awesome-Widget">
<directory>tests</directory>
</testsuite>
</testsuites>

<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
4 changes: 1 addition & 3 deletions src/Base/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ abstract class Widget implements ElementInterface
/**
* @psalm-param array<string, mixed> $definitions
*/
public function __construct(public readonly array $definitions = [])
{
}
public function __construct(public readonly array $definitions = []) {}

/**
* Allows not to call `->render()` explicitly:
Expand Down
7 changes: 6 additions & 1 deletion tests/Factory/ExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public function testConfigure(): void
'The provided widget must be an instance of "PHPForge\Widget\Base\Widget", "stdClass" given.'
);

SimpleFactory::configure(new stdClass(), ['id()' => ['id-configure']]);
SimpleFactory::configure(
new stdClass(),
[
'id()' => ['id-configure'],
]
);
}
}
Loading

0 comments on commit 838268d

Please sign in to comment.