11<?php
22/**
3- * Copyright 2017 Adobe All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2017 Adobe
4+ * All Rights Reserved .
55 */
66declare (strict_types=1 );
77
1616use Magento \Framework \Setup \Declaration \Schema \Sharding ;
1717use Magento \Framework \Config \FileResolverByModule ;
1818use Magento \Framework \Setup \Declaration \Schema \Declaration \ReaderComposite ;
19+ use Psr \Log \LoggerInterface ;
20+ use Magento \Framework \Exception \LocalizedException ;
1921
2022/**
2123 * This type of builder is responsible for converting ENTIRE data, that comes from db
2729 *
2830 * @see Schema
2931 * @inheritdoc
32+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3033 */
3134class SchemaBuilder
3235{
@@ -55,30 +58,39 @@ class SchemaBuilder
5558 */
5659 private $ readerComposite ;
5760
61+ /**
62+ * @var LoggerInterface
63+ */
64+ private $ logger ;
65+
5866 /**
5967 * Constructor.
6068 *
6169 * @param ElementFactory $elementFactory
6270 * @param DbSchemaReaderInterface $dbSchemaReader
6371 * @param Sharding $sharding
6472 * @param ReaderComposite $readerComposite
73+ * @param LoggerInterface $logger
6574 */
6675 public function __construct (
6776 ElementFactory $ elementFactory ,
6877 DbSchemaReaderInterface $ dbSchemaReader ,
6978 Sharding $ sharding ,
70- ReaderComposite $ readerComposite
79+ ReaderComposite $ readerComposite ,
80+ LoggerInterface $ logger
7181 ) {
7282 $ this ->elementFactory = $ elementFactory ;
7383 $ this ->dbSchemaReader = $ dbSchemaReader ;
7484 $ this ->sharding = $ sharding ;
7585 $ this ->readerComposite = $ readerComposite ;
86+ $ this ->logger = $ logger ;
7687 }
7788
7889 /**
7990 * @inheritdoc
8091 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
8192 * @SuppressWarnings(PHPMD.NPathComplexity)
93+ * @throws LocalizedException
8294 */
8395 public function build (Schema $ schema )
8496 {
@@ -100,10 +112,10 @@ public function build(Schema $schema)
100112 $ keyTable ,
101113 $ keyColumn
102114 );
103-
115+ $ this -> logger -> error ( $ errorMessage );
104116 // Throw a new exception with the extended message
105117 // This preserves the original error but adds our context
106- throw new \ Exception ( $ errorMessage , $ e -> getCode (), $ e );
118+ throw new LocalizedException ( new Phrase ( $ errorMessage ) );
107119 }
108120 }
109121 }
0 commit comments