From 6e87308c0017dd59ccb5a704381d9678d36be07b Mon Sep 17 00:00:00 2001 From: Simon Dann Date: Thu, 23 Nov 2017 01:29:10 +0000 Subject: [PATCH] :art: tidy up --- src/Entities/ContentType.php | 21 ++++++++++++++------- src/Entities/Environment.php | 6 ++++-- src/Entities/File.php | 3 ++- src/Entities/FrontMatter.php | 9 ++++++--- src/Entities/Taxonomy.php | 9 ++++++--- src/Exporter.php | 12 +++++------- src/Hydrators/File.php | 6 +++--- src/ServiceProvider.php | 12 +++++------- src/Synchronizes/ContentTypes.php | 18 ++++++++++-------- src/Synchronizes/Files.php | 3 ++- 10 files changed, 57 insertions(+), 42 deletions(-) diff --git a/src/Entities/ContentType.php b/src/Entities/ContentType.php index 07a31c1..d1aa8b1 100644 --- a/src/Entities/ContentType.php +++ b/src/Entities/ContentType.php @@ -14,37 +14,44 @@ class ContentType { /** * @var int - * @Id @Column(type="integer") @GeneratedValue */ + * @Id @Column(type="integer") @GeneratedValue + */ private $id; /** * @var Environment - * @ManyToOne(targetEntity="Environment") */ + * @ManyToOne(targetEntity="Environment") + */ private $environment; /** * @var string - * @Column(type="string") */ + * @Column(type="string") + */ private $name; /** * @var string - * @Column(type="string") */ + * @Column(type="string") + */ private $path; /** * @var string - * @Column(type="string") */ + * @Column(type="string") + */ private $template; /** * @var string - * @Column(type="string") */ + * @Column(type="string") + */ private $permalink; /** * @var bool - * @Column(type="boolean") */ + * @Column(type="boolean") + */ private $enabled; /** diff --git a/src/Entities/Environment.php b/src/Entities/Environment.php index 98e1e99..4230e9a 100644 --- a/src/Entities/Environment.php +++ b/src/Entities/Environment.php @@ -43,7 +43,8 @@ public function getContentTypes() return $this->contentTypes; } - public function addContentType(ContentType $contentType) { + public function addContentType(ContentType $contentType) + { $this->contentTypes[] = $contentType; } @@ -52,7 +53,8 @@ public function getFiles() return $this->files; } - public function addFile(File $file) { + public function addFile(File $file) + { $this->files[] = $file; } } \ No newline at end of file diff --git a/src/Entities/File.php b/src/Entities/File.php index 1482a9f..43c610f 100644 --- a/src/Entities/File.php +++ b/src/Entities/File.php @@ -116,7 +116,8 @@ public function setEnvironment(Environment $environment) $this->environment = $environment; } - public function addFrontMatter(FrontMatter $frontMatter) { + public function addFrontMatter(FrontMatter $frontMatter) + { if ($this->frontMatter->contains($frontMatter)) { return; } diff --git a/src/Entities/FrontMatter.php b/src/Entities/FrontMatter.php index 1dd5b5b..8514b91 100644 --- a/src/Entities/FrontMatter.php +++ b/src/Entities/FrontMatter.php @@ -10,17 +10,20 @@ class FrontMatter { /** * @var int - * @Id @Column(type="integer") @GeneratedValue */ + * @Id @Column(type="integer") @GeneratedValue + */ private $id; /** * @var string - * @Column(type="string") */ + * @Column(type="string") + */ private $name; /** * @var string - * @Column(type="string") */ + * @Column(type="string") + */ private $value; /** @ManyToOne(targetEntity="File") */ diff --git a/src/Entities/Taxonomy.php b/src/Entities/Taxonomy.php index 3dcecb3..721946f 100644 --- a/src/Entities/Taxonomy.php +++ b/src/Entities/Taxonomy.php @@ -15,13 +15,15 @@ class Taxonomy /** * @var int * - * @Id @Column(type="integer") @GeneratedValue */ + * @Id @Column(type="integer") @GeneratedValue + */ private $id; /** * @var string * - * @Column(type="string") */ + * @Column(type="string") + */ private $name; @@ -74,7 +76,8 @@ public function getContentType() return $this->contentType; } - public function setContentType(ContentType $contentType) { + public function setContentType(ContentType $contentType) + { $this->contentType = $contentType; } diff --git a/src/Exporter.php b/src/Exporter.php index ed11409..fffb766 100644 --- a/src/Exporter.php +++ b/src/Exporter.php @@ -4,21 +4,18 @@ use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; -use PDO; use Symfony\Component\Console\Output\OutputInterface; use Tapestry\Entities\Collections\FlatCollection; use Tapestry\Entities\Project; -use Doctrine\DBAL\Connection; use Tapestry\Modules\ContentTypes\ContentTypeFactory; use Tapestry\Tapestry; -use TapestryCloud\Database\Entities\ContentType; use TapestryCloud\Database\Entities\Environment; -use TapestryCloud\Database\Entities\File; use TapestryCloud\Database\Synchronizes\ContentTypes; use TapestryCloud\Database\Synchronizes\Files; use TapestryCloud\Database\Hydrators\File as FileHydrator; -class Exporter { +class Exporter +{ /** * @var EntityManagerInterface|EntityManager */ @@ -40,7 +37,8 @@ public function __construct(EntityManagerInterface $entityManager, Tapestry $tap } - public function export(Project $project) { + public function export(Project $project) + { $this->output->writeln('[$] Syncing with database.'); @@ -53,7 +51,7 @@ public function export(Project $project) { /** @var array $cmdOptions */ $cmdOptions = $project->get('cmd_options'); - if (! $environment = $this->entityManager->getRepository(Environment::class)->findOneBy(['name' => $cmdOptions['env']])) { + if (!$environment = $this->entityManager->getRepository(Environment::class)->findOneBy(['name' => $cmdOptions['env']])) { $environment = new Environment(); $environment->setName($cmdOptions['env']); $this->entityManager->persist($environment); diff --git a/src/Hydrators/File.php b/src/Hydrators/File.php index c8a2f8c..387e2f5 100644 --- a/src/Hydrators/File.php +++ b/src/Hydrators/File.php @@ -18,7 +18,7 @@ class File extends Hydrator * @param \Tapestry\Entities\File $file * @param Environment|null $environment */ - public function hydrate(Model $model, \Tapestry\Entities\File $file, Environment $environment = null) + public function hydrate(Model $model, \Tapestry\Entities\File $file, Environment $environment = null) { $model->setUid($file->getUid()); $model->setLastModified($file->getLastModified()); @@ -27,10 +27,10 @@ public function hydrate(Model $model, \Tapestry\Entities\File $file, Environmen $model->setPath($file->getPath()); $model->setToCopy($file->isToCopy()); - if (! $file->isToCopy()) { + if (!$file->isToCopy()) { $frontMatter = new TapestryFrontMatter($file->getFileContent()); $model->setContent($frontMatter->getContent()); - foreach($frontMatter->getData() as $key => $value) { + foreach ($frontMatter->getData() as $key => $value) { $fmRecord = new FrontMatter(); $fmRecord->setName($key); $fmRecord->setValue(json_encode($value)); diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 626744a..8a99bb0 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -1,6 +1,7 @@ container property or the `getContainer` method @@ -29,13 +31,13 @@ class ServiceProvider extends AbstractServiceProvider implements BootableService public function register() { - $this->getContainer()->add(Connection::class, function() { + $this->getContainer()->add(Connection::class, function () { /** @var Configuration $configuration */ $configuration = $this->getContainer()->get(Configuration::class); return DriverManager::getConnection($configuration->get('plugins.database', []), new \Doctrine\DBAL\Configuration()); }); - $this->getContainer()->add(EntityManagerInterface::class, function() { + $this->getContainer()->add(EntityManagerInterface::class, function () { /** @var Configuration $configuration */ $configuration = $this->getContainer()->get(Configuration::class); @@ -49,12 +51,8 @@ public function register() ) ); }); - - // $this->getContainer()->add(Exporter::class, function() { - // - // return new Exporter(); - // }); } + /** * Method will be invoked on registration of a service provider implementing * this interface. Provides ability for eager loading of Service Providers. diff --git a/src/Synchronizes/ContentTypes.php b/src/Synchronizes/ContentTypes.php index 9af437c..8b35fec 100644 --- a/src/Synchronizes/ContentTypes.php +++ b/src/Synchronizes/ContentTypes.php @@ -27,9 +27,10 @@ public function __construct(EntityManagerInterface $em) $this->em = $em; } - public function sync(ContentTypeFactory $contentTypeFactory, Environment $environment) { - foreach($contentTypeFactory->all() as $contentType) { - if (!$record = $this->em->getRepository(ContentType::class)->findOneBy(['name' => $contentType->getName(), 'environment' => $environment->getId()])){ + public function sync(ContentTypeFactory $contentTypeFactory, Environment $environment) + { + foreach ($contentTypeFactory->all() as $contentType) { + if (!$record = $this->em->getRepository(ContentType::class)->findOneBy(['name' => $contentType->getName(), 'environment' => $environment->getId()])) { // INSERT $record = new ContentType(); $record->hydrate($contentType, $environment); @@ -49,9 +50,10 @@ public function sync(ContentTypeFactory $contentTypeFactory, Environment $enviro * @param TapestryTaxonomy[] $taxonomies * @param Environment $environment */ - private function syncTaxonomyToContentType(ContentType $contentType, array $taxonomies, Environment $environment) { + private function syncTaxonomyToContentType(ContentType $contentType, array $taxonomies, Environment $environment) + { /** @var TapestryTaxonomy $taxonomy */ - foreach($taxonomies as $taxonomy) { + foreach ($taxonomies as $taxonomy) { if (!$record = $this->em->getRepository(Taxonomy::class)->findOneBy(['name' => $taxonomy->getName()])) { $record = new Taxonomy(); $record->hydrate($taxonomy); @@ -64,7 +66,7 @@ private function syncTaxonomyToContentType(ContentType $contentType, array $taxo } foreach ($taxonomy->getFileList() as $classification => $files) { - if (! $classificationRecord = $this->em->getRepository(Classification::class)->findOneBy(['name' => $classification])){ + if (!$classificationRecord = $this->em->getRepository(Classification::class)->findOneBy(['name' => $classification])) { $classificationRecord = new Classification(); $classificationRecord->setName($classification); $this->em->persist($classificationRecord); @@ -73,9 +75,9 @@ private function syncTaxonomyToContentType(ContentType $contentType, array $taxo $classificationRecord->addTaxonomy($record); $this->em->flush(); - foreach(array_keys($files) as $filename) { + foreach (array_keys($files) as $filename) { /** @var File $file */ - if ($file = $this->em->getRepository(File::class)->findOneBy(['uid' => $filename, 'environment' => $environment->getId()])){ + if ($file = $this->em->getRepository(File::class)->findOneBy(['uid' => $filename, 'environment' => $environment->getId()])) { $file->addClassification($classificationRecord); $this->em->persist($file); } diff --git a/src/Synchronizes/Files.php b/src/Synchronizes/Files.php index 784e97f..7665aa3 100644 --- a/src/Synchronizes/Files.php +++ b/src/Synchronizes/Files.php @@ -32,7 +32,8 @@ public function __construct(EntityManagerInterface $em, FileHydrator $fileHydrat $this->fileHydrator = $fileHydrator; } - public function sync(FlatCollection $files, Environment $environment) { + public function sync(FlatCollection $files, Environment $environment) + { /** @var TapestryFile $file */ foreach ($files as $file) {