Skip to content

Commit

Permalink
refactor: improving doc & tests
Browse files Browse the repository at this point in the history
  • Loading branch information
siganushka committed Jul 1, 2024
1 parent f912c1c commit 0ac83b8
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 20 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
### 安装

```bash
$ composer require siganushka/region-bundle --dev-main
$ composer require siganushka/region-bundle
```

### 使用

更新数据库映射信息:

```bash
$ php bin/console doctrine:schema:update --complete --force
$ php bin/console doctrine:schema:update --force
```

更新行政区划数据
更新行政区划数据源

```bash
$ php bin/console siganushka:region:update
Expand All @@ -41,7 +41,7 @@ siganushka_region:
> 导入后可通过 `php bin/console debug:route` 查看已导入路由。

### Twig
### Twig(可选)

导出前端资源到项目:

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"php": ">=7.4",
"doctrine/doctrine-bundle": "^2.8",
"doctrine/orm": "^2.11",
"siganushka/doctrine-contracts": "dev-main",
"siganushka/generic-bundle": "dev-main",
"siganushka/doctrine-contracts": "^0.1",
"siganushka/generic-bundle": "^0.6",
"symfony/form": "^5.4|^6.0",
"symfony/framework-bundle": "^5.4|^6.0",
"symfony/http-client": "^5.4|^6.0",
Expand Down
9 changes: 5 additions & 4 deletions src/Command/RegionUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
*/
class RegionUpdateCommand extends Command
{
protected static $defaultName = 'siganushka:region:update';
protected static $defaultDescription = '更新行政区划数据,来源 https://github.com/modood/Administrative-divisions-of-China';

private HttpClientInterface $httpClient;
private EntityManagerInterface $entityManager;

Expand All @@ -33,7 +30,11 @@ public function __construct(HttpClientInterface $httpClient, EntityManagerInterf

protected function configure(): void
{
$this->addOption('with-street', null, InputOption::VALUE_NONE, '是否包含乡/街道数据?');
$this
->setName('siganushka:region:update')
->setDescription('更新行政区划数据,来源 https://github.com/modood/Administrative-divisions-of-China')
->addOption('with-street', null, InputOption::VALUE_NONE, '是否包含乡/街道数据?')
;
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand Down
3 changes: 0 additions & 3 deletions src/DependencyInjection/SiganushkaRegionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

class SiganushkaRegionExtension extends Extension
{
/**
* @param array<mixed> $configs
*/
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new PhpFileLoader($container, new FileLocator(\dirname(__DIR__).'/Resources/config'));
Expand Down
7 changes: 3 additions & 4 deletions src/Resources/public/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ document.addEventListener('DOMContentLoaded', () => {
const { siganRegionTarget, siganRegionUrl } = event.target.dataset
const target = document.getElementById(siganRegionTarget)
if (target) {
let regions = []
const regions = []

const placeholder = target.querySelector('option[value=""]')
if (placeholder) {
regions.push({ code: '', name: placeholder.textContent })
}

if (event.target.value) {
const response = await fetch(`${siganRegionUrl}?parent=${event.target.value}`, {
headers: { Accept: 'application/json' }
})
const headers = { Accept: 'application/json' }
const response = await fetch(`${siganRegionUrl}?parent=${event.target.value}`, { headers })
regions.push(...await response.json())
}

Expand Down
3 changes: 0 additions & 3 deletions tests/Form/Type/AbstractRegionTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

abstract class AbstractRegionTypeTest extends AbstractRegionTest
{
/**
* @param mixed $data
*/
protected function createFormBuilder(string $type = FormType::class, $data = null, array $options = []): FormBuilderInterface
{
$formFactoryBuilder = new FormFactoryBuilder();
Expand Down

0 comments on commit 0ac83b8

Please sign in to comment.