PHP modernization approach generating KDM models from PHP legacy code

syntax tree meta-model (ASTM) Architecture-driven modernization (ADM) Knowledge discovery model (KDM) Model-driven engineering Reverse engineering This is an open access article under the CC BY-SA license. Corresponding Author: Amine Moutaouakkil, MISC Laboratory, Faculty of Science, Ibn Tofail University , BP133, Kenitra, Morocco. Email: amine.moutaouakkil@hotmail.fr


INTRODUCTION
Basing more and more their business on IT solutions, organizations using web technology systems have to modernize their legacy systems to be aligned with competition. Most of websites and web applications are written in PHP language (82,5% in 2017 -02-11). The need to immigrate both from and to this language is increasing. The PHP language is constantly evolving, more and more new frameworks and new standarts are available to use which make users in the need of migrating their PHP Web applications to another language or to a new version of PHP language.
It is necessary to have a standardized an automatic process of reengineering to minimize time and costs. Currently, there is an initiative to standardize and automa te the reengineering process. The Architecture-driven Modernization (ADM) [1] is an Object Management Group (OMG) [2] initiative related to the reverse engineering domain. This initiative has been proposed to enhance the classical reverse engineering processes by introducing the Model-driven Architecture (MDA) [3] concepts. In the same way that the MDA approach provides a leading role to the models, the ADM approach introduces several concepts to formalize the RE [4] processes based on models too.
It is necessary to realize methods for migrating PHP Web applications, but currently there are no relied ADM based methodes making it. We defined an ADM based approach to represent PHP source code in form of KDM models. This approach has taken advantage of the potential of the Architecture Driven Modernization (ADM) to modeling the knowledge, which will be extracted from the legacy program artifacts. In this article, we describe the generation of models to represent the legacy system at the highest level of abstraction. The rest of this article is organized as follows: section 2 describes the process based on the ADM approach and describes their different phases. In section 3, we illustrate our proposed approach by a case study. Section 4 makes the analysis of the process result. In section 5 we list some interesting related works. Finally, section 6 concludes the work and presents the perspectives.

RESEARCH METHOD -MDRE
Model Driven Reverse Engineering (MDRE) [5] is the application of Model Driven Engineering (MDE) principles and techniques to Reverse Engineering (RE) in order to get model based views from legacy systems. The MDRE is based on two main phases: Model Discovery which is extracting information from source code by using parsers, and then represent this information in form of models. And Model Understanding which is applying Model to Model transformations on extracted information to get a higher abstraction level presentation of the information.
-ADM Architecture Driven Modernization (ADM) is an initiative proposed by OMG to standardize and automate the reengineering process. ADM is based on three standards meta -models to represent the information involved in a software reengineering process. In the current study, only Abstract Syntax Tree Meta-Model (ASTM) [6] and Knowledge Discovery Meta -Model (KDM) standards are useful for the purpose. ASTM allows modeling the legacy code in form of Abstract Syntax Tree. Otherwise, KDM [7] allows defining models at a higher abstraction level representing semantic information about a software system.

Model discovery
Discovering the legacy system corresponding PSM models by analyze the source code constitutes the first step. PSM models define the structures and relationships between system elements. UML Class Diagram for example is a PSM model that can be generated by many UML tools: PowerAMC [8], Enterprise-Architect [9], Objecteering [10], Modelio [11], Papyrus [12]. Model discovery allows the extraction of information from the system and its representation in concrete models such as ASTM.
To represent the information in PHP code in the form of ASTM models, we have found out that we have to write a PHP Discoverer first so that existing PHP code can be represented as a model. After dealing with the creation and operation of discoverers. It turned out that the incorporation and imple mentation is extremely complex.
We looked for alternative ways to transform PHP code into models. After searching and trying the available parsers for PHP, one of them was interesting, glayzzle/php -parser [13]. This parser is working well, it parses the PHP code and gets an abstract syntax tree (AST), and obtained tree is an intermediate step to get ASTM models after transformations.

Model understanding
Model understanding consists in the transformation of models to get higher abstract models. In our study, we need to make two transformations: Apply model-to-model transformation on the AST tree to get ASTM model, which is a Generic ASTM model. Apply model-to-model transformation on the ASTM model to get KDM model. -QVT Transformation Standard QVT (Query/View/Transformation) [14] is a standard set of languages for model transformation defined by the OMG. The QVT standard defines three model transformation languages. All of them operate on models which conform to Meta-Object Facility (MOF) 2.0 metamodels; the transformation states which metamodels are used. QVT Operational which we use, it is an imperative language designed for writing unidirectional transformations. Models extraction process a shown in Figure 1.
-ASTM Current OMG ASTM meta -model needs to be simplified, to make the transformation easier for our example. ASTM meta -model provided by OMG and Simplified one a shown Figure 2.
-KDM KDM meta -model provided by OMG a shown in Figure 3. KDM is a standard defined by OMG for the representation of software systems. This meta -model allows to represent systems artifacts in a high level of abstraction. The KDM specification consists of 12 packages that are arranged into the following four layers [15].

Related works
More and more research projects use the mechanisms offered by the MDA, in among these projects include eg: -ADM-Based Hybrid Model Transformation for Obtaining UML Models from PHP Code [16] -Improving Consistency of UML Diagrams and Its Implementation Using Reverse Engineering Approach  [23] ADM-Based Hybrid Model Transformation for Obtaining UML Models from PHP Code (2019). This paper describes a model transformation process performing reverse engineering of PHP web applications. Model to model transformations are implemented using ATL [24] (Atlas Transformation Language). The obtained models are expressed in UML.
Improving Consistency of UML Diagrams and Its Implementation Using Reverse Engineering Approach (2018). This paper describse the development of a tool that improve the consistency between Unified Modeling Language (UML) design models and its C# implementation using reverse engineering approach. This approach also takes code source as input a pplying to it the reverse eenginering process, and then it takes the models as input too to verivying the consistency. This approach does not generate models as artifacts.
A Model Driven Approach based on Interaction Flow Modeling Language to Generate Rich Internet Applications (2016). This paper presents a model driven approach to generat GUI for Rich Internet Application. Using the language IFML adopted by the Object Management Group, Query View Transformation (QVT) for model transformations and Acceleo for code generation, the approach allows to generate a RIA focusing on the graphical aspect of the application. Java Swing Modernization Approach: Complete Abstract Representation based on Sta tic and Dynamic Analysis (2016). This paper defines an ADM-based method to define abstract models representing the GUI knowledge and automate the generation of these models through transformation chains. A Model Driven Reverse Engineering Framework for Extracting Business Rules o ut of a Java Application (2012). This paper proposes a process of extracting business rules out of a Java application, by identifying business rules from the source code. And presenting the extracted business rules through models.
Reverse Engineering Applied to CMS-Based Web Applications Coded in PHP: A Proposal of Migration (2013). This paper defines an ADM-based method for migrating CMS-based Web applications. This method is focused on open-source CMS which are implemented in PHP. It makes the implementation of the reverse engineering phase: ASTM models are extracted from the PHP code by text -to-model (T2M) transformation implemented by a source code parser, KDM models are generated from the previous ASTM models by means of M2M transformations. and by using M2 M transformations the CMS Model which conforms to the CMS Common Metamodel is generated. M2M transformations are implemented using ATL Transformation Language.
Combining UML Class and Activity Diagrams for MDA Generation of MVC 2 Web Applications (2013). This paper defines an MDA based process that integrates UML class diagram and Activity diagram, in order to generate MVC2 web model of e-commerce web applications. Model-to-model transformations are implemented using ATL Transformation Language, Model to text transformation are implemented using JET language [25]. MoDisco Project (2014). The eclipse plugin « Modisco » provides the capability of extracting information from Java software artifacts, The model resulting will conform to meta -model included in Modisco. Model of the abstract syntax tree can be obtained first from the program (based on a generic meta-model such as OMG ASTM), After a transformation, Model of KDM meta -model is obtained; KDM allows representing the entire software system and all its entities at both structural and behavioral levels. Extracted models by Modisco are Ecore models. Modisco is one of rare tools that have allowed to apply the ADM principles in rea l. Unfortunately, the current Modisco version does not include any specific support for PHP code.

Analysis and discussion
In the ADM approach, KDM plays an important role. It is a meta -model that allows to represent the structural and semantic aspect of the software systems artifacts in a high level of abstraction. As a syst em is represented in form of KDM models, the immigration to another platform becomes easier. We can notice that obtained result corresponds to our aim goal.
According to the related works we can conclude that ADM approaches that extra ct ASTM and KDM models from PHP code and others platforms are rare. Modisco approach stops at the Specific ASTM level. "java" models extract by Modisco from Java projects are not generic ASTM models. The approach " Reverse Engineering Applied to CMS-Based Web Applications Coded in PHP: A Proposal of Migration " is based on in the use of the Xtext [26] plugin witch allows defining the syntax of language, wich involves to write the PHP syntax in Xtext Grammar. Writing the PHP syntax in xtext language is a h ard and time-consuming task, this task is avoided in our approach by using glayzzle php-parser, our approach helps to gain this consumed time.

CONCLUSION
This paper presented an ADM based approach that allow obtaining KDM models from PHP source code. This approach is composed of two phases: 1) extracting AST tree from source code, in this phase the trees are extracted from the PHP code by text-to-model (T2M) transformations implem ented by a so u rce code parser, 2) Generation of ASTM models, KDM m odels are generated from the previous ASTM models by means of M2M transformations.For the implementation of the tree extraction phase, we have used Galyzzle PHP Parser which has allowed us to extract AST tree from the source code.For the implementation of the Generation of ASTM and KDM models phase we have implemented transformation rules using QVT-Operational language. The major contribution is the use of the QVT transformation language defined by the OMG. In addition, using this approach can reduce the necessary time to make the PHP web applications migration. As a future work, we will perform similar approach to other platform and compare high-level abstract results.