Class: Dev::Php

Inherits:
Object show all
Defined in:
lib/firespring_dev_commands/php.rb,
lib/firespring_dev_commands/php/audit.rb

Overview

Class containing methods related to php applicatio

Defined Under Namespace

Classes: Audit, Config

Constant Summary collapse

DEFAULT_PATH =

The default path of the application inside the container

'/usr/src/app'.freeze
DEFAULT_PACKAGE_FILE =

The default name of the php package file

'composer.json'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container_path: nil, local_path: nil, package_file: nil) ⇒ Php

Returns a new instance of Php.



35
36
37
38
39
# File 'lib/firespring_dev_commands/php.rb', line 35

def initialize(container_path: nil, local_path: nil, package_file: nil)
  @container_path = container_path || self.class.config.container_path
  @local_path = local_path || self.class.config.local_path
  @package_file = package_file || self.class.config.package_file
end

Instance Attribute Details

#container_pathObject

Returns the value of attribute container_path.



33
34
35
# File 'lib/firespring_dev_commands/php.rb', line 33

def container_path
  @container_path
end

#local_pathObject

Returns the value of attribute local_path.



33
34
35
# File 'lib/firespring_dev_commands/php.rb', line 33

def local_path
  @local_path
end

#package_fileObject

Returns the value of attribute package_file.



33
34
35
# File 'lib/firespring_dev_commands/php.rb', line 33

def package_file
  @package_file
end

Class Method Details

.config {|@config| ... } ⇒ Object Also known as: configure

Instantiates a new top level config object if one hasn’t already been created Yields that config object to any given block Returns the resulting config object

Yields:



23
24
25
26
27
# File 'lib/firespring_dev_commands/php.rb', line 23

def config
  @config ||= Config.new
  yield(@config) if block_given?
  @config
end

Instance Method Details

#audit_commandObject

Build the command which can be use to perform a security audit report



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/firespring_dev_commands/php.rb', line 47

def audit_command
  audit = base_command
  audit << 'audit'
  audit << '--no-interaction'
  audit << '--no-cache'
  audit << '--format' << 'json'
  audit.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s))
  audit << '2>&1' << '||' << 'true'

  # Run the command as part of a shell script
  ['sh', '-c', audit.join(' ')]
end

#base_commandObject

The base npm command that is the starting point for all subsequent commands



42
43
44
# File 'lib/firespring_dev_commands/php.rb', line 42

def base_command
  ['composer', '--working-dir', container_path]
end

#install_commandObject

Build the php install command



69
70
71
72
73
74
# File 'lib/firespring_dev_commands/php.rb', line 69

def install_command
  install = base_command
  install << 'install'
  install.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s))
  install
end

#lint_commandObject

Build the php lint command



77
78
79
80
81
82
# File 'lib/firespring_dev_commands/php.rb', line 77

def lint_command
  lint = base_command
  lint << 'lint'
  lint.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s))
  lint
end

#lint_fix_commandObject

Build the php lint fix command



85
86
87
88
89
90
# File 'lib/firespring_dev_commands/php.rb', line 85

def lint_fix_command
  lint_fix = base_command
  lint_fix << 'lint-fix'
  lint_fix.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s))
  lint_fix
end

#test_commandObject

Build the php test command



93
94
95
96
97
98
# File 'lib/firespring_dev_commands/php.rb', line 93

def test_command
  test = []
  test << './vendor/bin/phpunit'
  test.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s))
  test
end

#test_fast_command(processes = 4) ⇒ Object

Build the php fast test command



101
102
103
104
105
106
107
# File 'lib/firespring_dev_commands/php.rb', line 101

def test_fast_command(processes = 4)
  test = []
  test << './vendor/bin/paratest'
  test.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s))
  test << "-p#{processes}" << '--runner=WrapperRunner'
  test
end