|
1 |
| -# Dhii - PHP Project |
2 |
| -[](https://github.com/dhii/php-project/actions/workflows/continuous-integration.yml) |
| 1 | +# WP HTTP Client |
| 2 | +[](https://github.com/wp-oop/http-client/actions/workflows/continuous-integration.yml) |
| 3 | +[][packagist] |
| 4 | +[][packagist] |
| 5 | +[][packagist] |
3 | 6 |
|
4 |
| -A PHP starter to ease project creation |
| 7 | +A PSR-18 wrapper for the [WordPress HTTP API][wp-http-api]. |
5 | 8 |
|
6 |
| -## Details |
7 |
| -Use this project as a starter for your PHP library! |
8 |
| - |
9 |
| -### Feaures |
10 |
| -- **Docker** - Develop and test your plugin with Docker. Use an environment |
11 |
| - tailored for your plugin. See changes instantly in the browser. Build |
12 |
| - a Docker image containing a complete WordPress installation with your |
13 |
| - plugin and all pre-requisites. |
14 |
| - |
15 |
| -- **PHPStorm** - Configuration for integrations of arguably the best PHP |
16 |
| - IDE out there, including: |
17 |
| - |
18 |
| - * **Composer** - Install and manage PHP dependencies on the correct version of PHP without leaving the IDE. |
19 |
| - * **PHPUnit** - Run tests and get reports directly in PHPStorm. |
20 |
| - * **xDebug** - Set breakpoints and inspect your code in PHPStorm. |
21 |
| - * **Code coverage** - See what has not been tested yet in a friendly GUI. |
22 |
| - |
23 |
| -- **Static Code Analysis** - Maintain a consistent coding style, and catch problems early. |
24 |
| - |
25 |
| - * **[Psalm][]** - Inspects your code for problems. |
26 |
| - * **[PHPCS][]** - Checks your code style. [PHPCBF][] can fix some of them automatically. |
27 |
| - |
28 |
| -- **Continuous Integration** - Automatically verify that all contributions comply with |
29 |
| - project standards with [GitHub Actions][]. |
30 |
| - |
31 |
| -### Usage |
32 |
| - |
33 |
| -#### Getting Started |
34 |
| -Use Composer to bootstrap your project. |
35 |
| - |
36 |
| -1. Clone and install deps: |
37 |
| - |
38 |
| - ```bash |
39 |
| - composer create-project dhii/php-project my_project |
40 |
| - ``` |
41 |
| - |
42 |
| - Here, `my_project` is the name of the project folder. |
43 |
| - |
44 |
| -2. Customize project |
45 |
| - |
46 |
| - _Note_: Asterisk `*` below denotes that changing this value requires rebuild of the images in order |
47 |
| - to have effect on the dev environment. |
48 |
| - |
49 |
| - - Copy `.env.example` to `.env`. |
50 |
| - - `.env`: |
51 |
| - * `BASE_PATH` - If you are using [Docker Machine][], i.e. on any non-Linux system, set this |
52 |
| - to the absolute path to the project folder _inside the machine_. If you are on Linux, |
53 |
| - you do not need to change this. |
54 |
| - * `PROJECT_NAME` - Slug of your project. Used mainly for naming containers with [`container_name`][]. |
55 |
| - This is helpful to run multiple projects on the same machine. |
56 |
| - * `PHP_BUILD_VERSION` - The version of PHP, on which the plugin will be _built_. This should |
57 |
| - correspond to the minimal PHP requirement of your plugin. Used to determine the tag of |
58 |
| - the [`php`][] image. |
59 |
| - * `PHP_TEST_VERSION`* - The version of PHP, on which the plugin will be _run_. This should |
60 |
| - correspond to the maximal PHP requirement of your plugin. Used to determine the tag of |
61 |
| - the [`php`][] image. |
62 |
| - |
63 |
| - - `composer.json`: |
64 |
| - * `name` - Name of your package. |
65 |
| - * `description` - Description of your package. |
66 |
| - * `authors` - You and/or your company details. |
67 |
| - * `require` - Your project's package and platform requirements. You may want to change the PHP |
68 |
| - version if your minimal requirement is different. Don't forget to update `PHP_BUILD_VERSION` |
69 |
| - in `.env`. |
70 |
| - * `require-dev` - Your project's development requirements. Tools for testing and code quality. |
71 |
| -
|
72 |
| -#### Updating Dependencies |
73 |
| -Composer is installed into the `build` service's image. To run composer commands, |
74 |
| -use `docker-compose run`. For example, to update dependencies you can run the following: |
75 |
| - |
76 |
| -```bash |
77 |
| -docker-compose run --rm build composer update |
78 |
| -``` |
79 |
| - |
80 |
| -If you use PHPStorm, you can use the [composer integration][], as the project |
81 |
| -is already configured for this. |
82 |
| - |
83 |
| -#### Testing Code |
84 |
| -This bootstrap includes PHPUnit. It is already configured, and you can test |
85 |
| -that it's working by running the sample tests: |
86 |
| -
|
87 |
| -```bash |
88 |
| -docker-compose run --rm test vendor/bin/phpunit |
89 |
| -``` |
90 |
| -
|
91 |
| -If you use PHPStorm, you can use its PHPUnit integration: right-click on any |
92 |
| -test or folder inside the `tests` directory, and choose "Run". This will do |
93 |
| -the same as the above command. Because the `test` service is used for tests, |
94 |
| -they will be run with its PHP version, which should correspond to your project's |
95 |
| -minimal requirements, but can be something else if you want to test on a system |
96 |
| -that has different specs. |
97 |
| - |
98 |
| -#### Debugging |
99 |
| -The bootstrap includes xDebug in the `test` service of the Docker environment, |
100 |
| -and PHPStorm configuration. To use it, right click on any test or folder within |
101 |
| -the `tests` directory, and choose "Debug". This will run the tests with xDebug |
102 |
| -enabled. If you receive the error about [`xdebug.remote_host`][] being set |
103 |
| -incorrectly and suggesting to fix the error, fix it by setting that variable |
104 |
| -to [your machine's IP address][] on the local network in the window that |
105 |
| -pops up. After this, breakpoints in any code reachable by PHPUnit tests, |
106 |
| -including the code of tests themselves, will cause execution to pause, |
107 |
| -allowing inspection of code. |
108 |
| -
|
109 |
| -#### Static Analysis |
110 |
| -- **Psalm** |
111 |
| -
|
112 |
| - Run Psalm in project root: |
113 |
| -
|
114 |
| - ```bash |
115 |
| - docker-compose run --rm test vendor/bin/psalm |
116 |
| - ``` |
117 |
| - |
118 |
| - * Will also be run automatically on CI. |
119 |
| - * PHPStorm integration config included. |
120 |
| - |
121 |
| -- **PHPCS** |
122 |
| -
|
123 |
| - Run PHPCS/PHPCBF in project root: |
124 |
| - |
125 |
| - ```bash |
126 |
| - docker-compose run --rm test vendor/bin/phpcs -s --report-source --runtime-set ignore_warnings_on_exit 1 |
127 |
| - docker-compose run --rm test vendor/bin/phpcbf |
128 |
| - ``` |
129 |
| - |
130 |
| - * By default, uses [PSR-12][] and some rules from the [Slevomat Coding Standard][]. |
131 |
| - * Will also be run automatically on CI. |
132 |
| - * PHPStorm integration config included. |
133 |
| -
|
134 |
| - |
135 |
| -[Docker Machine]: https://github.com/docker/machine |
136 |
| -[PSR-12]: https://www.php-fig.org/psr/psr-12/ |
137 |
| -[Slevomat Coding Standard]: https://github.com/slevomat/coding-standard |
138 |
| -[Psalm]: https://psalm.dev/ |
139 |
| -[PHPCS]: https://github.com/squizlabs/PHP_CodeSniffer |
140 |
| -[PHPCBF]: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Fixing-Errors-Automatically |
141 |
| -[GitHub Actions]: https://github.com/features/actions |
142 |
| -[hosts file]: https://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/ |
143 |
| -[your machine's IP address]: https://www.whatismybrowser.com/detect/what-is-my-local-ip-address |
144 |
| -[composer integration]: https://www.jetbrains.com/help/phpstorm/using-the-composer-dependency-manager.html#updating-dependencies |
145 |
| -[`container_name`]: https://docs.docker.com/compose/compose-file/#container_name |
146 |
| -[`php`]: https://hub.docker.com/_/php |
147 |
| -[`docker-machine start`]: https://docs.docker.com/machine/reference/start/] |
148 |
| -[`docker-machine env`]: https://docs.docker.com/machine/reference/env/ |
149 |
| -[`xdebug.remote_host`]: https://xdebug.org/docs/all_settings#remote_host |
| 9 | +[packagist]: https://packagist.org/packages/wp-oop/http-client |
| 10 | +[wp-http-api]: https://developer.wordpress.org/plugins/http-api/ |
0 commit comments